equal
deleted
inserted
replaced
22 |
22 |
23 def tearDown(self): |
23 def tearDown(self): |
24 self._cleanup() |
24 self._cleanup() |
25 |
25 |
26 def test(self): |
26 def test(self): |
27 lock = threading.Lock() |
27 lock1 = threading.Lock() |
28 |
28 lock2 = threading.Lock() |
|
29 |
29 def run_thread(): |
30 def run_thread(): |
30 cnx2 = get_connection('sqlite', database=self.sqlite_file) |
31 cnx2 = get_connection('sqlite', database=self.sqlite_file) |
31 lock.acquire() |
32 lock1.acquire() |
32 cu = cnx2.cursor() |
33 cu = cnx2.cursor() |
33 cu.execute('SELECT name FROM toto') |
34 cu.execute('SELECT name FROM toto') |
34 self.failIf(cu.fetchall()) |
35 self.failIf(cu.fetchall()) |
35 cnx2.commit() |
36 cnx2.commit() |
36 lock.release() |
37 lock1.release() |
37 time.sleep(0.1) |
38 lock2.acquire() |
38 lock.acquire() |
|
39 cu.execute('SELECT name FROM toto') |
39 cu.execute('SELECT name FROM toto') |
40 self.failUnless(cu.fetchall()) |
40 self.failUnless(cu.fetchall()) |
41 lock.release() |
41 lock2.release() |
42 |
42 |
43 cnx1 = get_connection('sqlite', database=self.sqlite_file) |
43 cnx1 = get_connection('sqlite', database=self.sqlite_file) |
44 lock.acquire() |
44 lock1.acquire() |
|
45 lock2.acquire() |
45 thread = threading.Thread(target=run_thread) |
46 thread = threading.Thread(target=run_thread) |
46 thread.start() |
47 thread.start() |
47 cu = cnx1.cursor() |
48 cu = cnx1.cursor() |
48 cu.execute('SELECT name FROM toto') |
49 cu.execute('SELECT name FROM toto') |
49 lock.release() |
50 lock1.release() |
50 time.sleep(0.1) |
|
51 cnx1.commit() |
51 cnx1.commit() |
52 lock.acquire() |
|
53 cu.execute("INSERT INTO toto(name) VALUES ('toto')") |
52 cu.execute("INSERT INTO toto(name) VALUES ('toto')") |
54 cnx1.commit() |
53 cnx1.commit() |
55 lock.release() |
54 lock2.release() |
56 |
55 |
57 if __name__ == '__main__': |
56 if __name__ == '__main__': |
58 unittest_main() |
57 unittest_main() |