|
7 | 7 | # you should have received as part of this distribution.
|
8 | 8 |
|
9 | 9 | from datetime import datetime
|
| 10 | +import functools |
10 | 11 | import multiprocessing
|
11 | 12 | import os
|
12 | 13 | import os.path
|
@@ -847,8 +848,33 @@ def test_startkey(self):
|
847 | 848 | def test_nullkeys(self):
|
848 | 849 | self.assertEqual(len(list(self.db.iterview('test/nulls', 10))), self.num_docs)
|
849 | 850 |
|
| 851 | + |
| 852 | +def _get_by_id(db, result, id): |
| 853 | + result.append(db[id]) |
| 854 | + |
| 855 | + |
| 856 | +class TestConcurrent(testutil.TempDatabaseMixin, unittest.TestCase): |
| 857 | + def test_concurrent_get(self): |
| 858 | + self.db.save({'_id': 'foo', 'value': 'hello'}) |
| 859 | + self.db.save({'_id': 'bar', 'value': 'world'}) |
| 860 | + processes = [] |
| 861 | + result = multiprocessing.Manager().list() |
| 862 | + for id in ('foo', 'bar'): |
| 863 | + process = multiprocessing.Process(target=functools.partial(_get_by_id, self.db, result), |
| 864 | + args=(id,)) |
| 865 | + processes.append(process) |
| 866 | + process.start() |
| 867 | + |
| 868 | + for process in processes: |
| 869 | + process.join() |
| 870 | + |
| 871 | + self.assertEqual(len(result), 2) |
| 872 | + self.assertEqual(set(['hello', 'world']), set([r['value'] for r in result])) |
| 873 | + |
| 874 | + |
850 | 875 | def suite():
|
851 | 876 | suite = unittest.TestSuite()
|
| 877 | + suite.addTest(unittest.makeSuite(TestConcurrent, 'test')) |
852 | 878 | suite.addTest(unittest.makeSuite(ServerTestCase, 'test'))
|
853 | 879 | suite.addTest(unittest.makeSuite(DatabaseTestCase, 'test'))
|
854 | 880 | suite.addTest(unittest.makeSuite(ViewTestCase, 'test'))
|
|
0 commit comments