Skip to content

Commit cd14892

Browse files
committed
Add concurrency test
1 parent f8a7a00 commit cd14892

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

couchdb/tests/client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# you should have received as part of this distribution.
88

99
from datetime import datetime
10+
import functools
1011
import multiprocessing
1112
import os
1213
import os.path
@@ -847,8 +848,33 @@ def test_startkey(self):
847848
def test_nullkeys(self):
848849
self.assertEqual(len(list(self.db.iterview('test/nulls', 10))), self.num_docs)
849850

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+
850875
def suite():
851876
suite = unittest.TestSuite()
877+
suite.addTest(unittest.makeSuite(TestConcurrent, 'test'))
852878
suite.addTest(unittest.makeSuite(ServerTestCase, 'test'))
853879
suite.addTest(unittest.makeSuite(DatabaseTestCase, 'test'))
854880
suite.addTest(unittest.makeSuite(ViewTestCase, 'test'))

0 commit comments

Comments
 (0)