diff options
author | Victor Shyba <victor.shyba@gmail.com> | 2015-08-06 16:39:18 -0300 |
---|---|---|
committer | Bruno Wagner <bwgpro@gmail.com> | 2015-08-12 17:17:18 -0300 |
commit | af3ebd56742fa6348935e0e013da9822ae4bd301 (patch) | |
tree | 7e8d6aab7f7619a1f8f9d20e3090a57ae0b8fb49 /common | |
parent | 09da43e222af9a19624e003ff22a8fa634ed059d (diff) |
[bug] fixes concurrent sync and their tests
Changes threading.lock to DeferredLock and checks syncing attribute by
looking into the lock state.
Also, applies more of startTwistedServer on tests that relies on
HTTP/1.1.
Fixes mock for events
Diffstat (limited to 'common')
4 files changed, 17 insertions, 24 deletions
diff --git a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py index 8f7af8c9..be36ddee 100644 --- a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py +++ b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py @@ -96,6 +96,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): replica_uid='replica', ensure_ddocs=True) self.tempdir = tempfile.mkdtemp(prefix="leap_tests-") + self.startTwistedServer() def tearDown(self): self.db.delete_database() @@ -164,7 +165,6 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): """ Assert that the sync_log increases accordingly with sequential syncs. """ - self.startServer() sol = self._soledad_instance( auth_token='auth-token', server_url=self.getURL()) @@ -321,8 +321,6 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): """ docs = [] - self.startServer() - sol = self._soledad_instance( auth_token='auth-token', server_url=self.getURL()) @@ -357,6 +355,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): return d + @defer.inlineCallbacks def test_concurrent_syncs_do_not_fail(self): """ Assert that concurrent attempts to sync end up being executed @@ -364,8 +363,6 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): """ docs = [] - self.startServer() - sol = self._soledad_instance( auth_token='auth-token', server_url=self.getURL()) @@ -374,21 +371,15 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): for i in xrange(0, REPEAT_TIMES): d = sol.create_doc({}) d.addCallback(lambda doc: docs.append(doc.doc_id)) - d.addCallback(lambda _: sol.sync()) + d.addCallback(sol.sync) deferreds.append(d) + yield defer.gatherResults(deferreds, consumeErrors=True) - def _assert_logs(results): - transaction_log = self.db._get_transaction_log() - self.assertEqual(REPEAT_TIMES, len(transaction_log)) - # assert all documents are in the remote log - self.assertEqual(REPEAT_TIMES, len(docs)) - for doc_id in docs: - self.assertEqual( - 1, - len(filter(lambda t: t[0] == doc_id, transaction_log))) - - d = defer.gatherResults(deferreds) - d.addCallback(_assert_logs) - d.addCallback(lambda _: sol.close()) - - return d + transaction_log = self.db._get_transaction_log() + self.assertEqual(REPEAT_TIMES, len(transaction_log)) + # assert all documents are in the remote log + self.assertEqual(REPEAT_TIMES, len(docs)) + for doc_id in docs: + self.assertEqual( + 1, + len(filter(lambda t: t[0] == doc_id, transaction_log))) diff --git a/common/src/leap/soledad/common/tests/test_server.py b/common/src/leap/soledad/common/tests/test_server.py index 848b68e9..17827486 100644 --- a/common/src/leap/soledad/common/tests/test_server.py +++ b/common/src/leap/soledad/common/tests/test_server.py @@ -347,7 +347,7 @@ class EncryptedSyncTestCase( Test the complete syncing chain between two soledad dbs using a Soledad server backed by a couch database. """ - self.startServer() + self.startTwistedServer() user = 'user-' + uuid4().hex # instantiate soledad and create a document diff --git a/common/src/leap/soledad/common/tests/test_soledad.py b/common/src/leap/soledad/common/tests/test_soledad.py index 8c791672..1217b763 100644 --- a/common/src/leap/soledad/common/tests/test_soledad.py +++ b/common/src/leap/soledad/common/tests/test_soledad.py @@ -361,7 +361,7 @@ class SoledadSignalingTestCase(BaseSoledadTest): def _assert_done_data_sync_signal_emitted(results): # assert the signal has been emitted - soledad.client.signal.assert_called_with( + soledad.client.events.emit.assert_called_with( catalog.SOLEDAD_DONE_DATA_SYNC, ADDRESS, ) diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py index df405010..9800078d 100644 --- a/common/src/leap/soledad/common/tests/util.py +++ b/common/src/leap/soledad/common/tests/util.py @@ -275,7 +275,7 @@ class BaseSoledadTest(BaseLeapTest, MockedSharedDBTest): MockSharedDB = self.get_default_shared_mock( _put_doc_side_effect) - return Soledad( + soledad = Soledad( user, passphrase, secrets_path=os.path.join( @@ -287,6 +287,8 @@ class BaseSoledadTest(BaseLeapTest, MockedSharedDBTest): defer_encryption=self.defer_sync_encryption, shared_db=MockSharedDB(), auth_token=auth_token) + self.addCleanup(soledad.close) + return soledad def assertGetEncryptedDoc( self, db, doc_id, doc_rev, content, has_conflicts): |