-
Notifications
You must be signed in to change notification settings - Fork 2
/
livetest.py
63 lines (45 loc) · 1.47 KB
/
livetest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Test of concurrent indexing using PGTextIndex"""
from repoze.pgtextindex.index import PGTextIndex
from repoze.pgtextindex.interfaces import IWeightedText
from threading import Thread
from zope.interface import implements
import logging
import thread
import transaction
class Thing(object):
implements(IWeightedText)
def __init__(self, docid, title, text):
self.docid = docid
self.title = title
self.text = text
@property
def A(self):
return self.title
def __str__(self):
return self.text
def discriminate_thing(thing, default):
return thing
def main():
logging.basicConfig()
dsn = "dbname='pgtxtest' user='pgtxtest' password='pgtxtest'"
main_index = PGTextIndex(discriminator=discriminate_thing,
dsn=dsn,
drop_and_create=True)
# Try to expose a bug in concurrent indexing.
def reindex_loop():
index = PGTextIndex(discriminator=discriminate_thing, dsn=dsn)
for j in range(1000):
obj10 = Thing(10, "Document", "Document body %d from thread %s"
% (j, thread.get_ident()))
index.index_doc(obj10.docid, obj10)
transaction.commit()
threads = []
for _i in range(8):
t = Thread(target=reindex_loop)
threads.append(t)
t.start()
for t in threads:
t.join()
print main_index.apply('body')
if __name__ == '__main__':
main()