1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 |
18 |
19 from datetime import datetime |
19 from datetime import datetime |
|
20 from threading import Thread |
20 |
21 |
21 from logilab.common.testlib import SkipTest |
22 from logilab.common.testlib import SkipTest |
22 |
23 |
23 from cubicweb.devtools import PostgresApptestConfiguration |
24 from cubicweb.devtools import PostgresApptestConfiguration |
24 from cubicweb.devtools.testlib import CubicWebTC |
25 from cubicweb.devtools.testlib import CubicWebTC |
27 |
28 |
28 from unittest_querier import FixedOffset |
29 from unittest_querier import FixedOffset |
29 |
30 |
30 class PostgresFTITC(CubicWebTC): |
31 class PostgresFTITC(CubicWebTC): |
31 configcls = PostgresApptestConfiguration |
32 configcls = PostgresApptestConfiguration |
|
33 |
|
34 def test_eid_range(self): |
|
35 # concurrent allocation of eid ranges |
|
36 source = self.session.repo.sources_by_uri['system'] |
|
37 range1 = [] |
|
38 range2 = [] |
|
39 def allocate_eid_ranges(session, target): |
|
40 for x in xrange(1, 10): |
|
41 eid = source.create_eid(session, count=x) |
|
42 target.extend(range(eid-x, eid)) |
|
43 |
|
44 t1 = Thread(target=lambda: allocate_eid_ranges(self.session, range1)) |
|
45 t2 = Thread(target=lambda: allocate_eid_ranges(self.session, range2)) |
|
46 t1.start() |
|
47 t2.start() |
|
48 t1.join() |
|
49 t2.join() |
|
50 self.assertEqual(range1, sorted(range1)) |
|
51 self.assertEqual(range2, sorted(range2)) |
|
52 self.assertEqual(set(), set(range1) & set(range2)) |
32 |
53 |
33 def test_occurence_count(self): |
54 def test_occurence_count(self): |
34 req = self.request() |
55 req = self.request() |
35 c1 = req.create_entity('Card', title=u'c1', |
56 c1 = req.create_entity('Card', title=u'c1', |
36 content=u'cubicweb cubicweb cubicweb') |
57 content=u'cubicweb cubicweb cubicweb') |