summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2016-08-02 00:07:13 -0300
committerdrebs <drebs@leap.se>2016-08-02 11:51:14 -0300
commit1c8b39b808a5d5b56f5463d29ad1a7e901bf84d5 (patch)
treec47f13f86f9ea9ec60fb105921204c6b08d4a11e
parente315847bd06bb575505720bd7e882e07406b1fab (diff)
[test] avoid race condition on test_processing_order
test_processing_order aims to check that unordered docs wont be processed, but if we let the pool start and advance Twisted LoopingCall clock right before calling the processing method manually, the process method will run concurrently and cause a race condition issue.
-rw-r--r--client/src/leap/soledad/client/encdecpool.py5
-rw-r--r--testing/tests/sync/test_encdecpool.py9
2 files changed, 7 insertions, 7 deletions
diff --git a/client/src/leap/soledad/client/encdecpool.py b/client/src/leap/soledad/client/encdecpool.py
index a6d49b21..2cf5da6e 100644
--- a/client/src/leap/soledad/client/encdecpool.py
+++ b/client/src/leap/soledad/client/encdecpool.py
@@ -344,6 +344,9 @@ class SyncDecrypterPool(SyncEncryptDecryptPool):
self._loop = LoopingCall(self._decrypt_and_recurse)
+ def _start_pool(self, period):
+ self._loop.start(period)
+
def start(self, docs_to_process):
"""
Set the number of documents we expect to process.
@@ -360,7 +363,7 @@ class SyncDecrypterPool(SyncEncryptDecryptPool):
self._docs_to_process = docs_to_process
self._deferred = defer.Deferred()
d = self._init_db()
- d.addCallback(lambda _: self._loop.start(self.DECRYPT_LOOP_PERIOD))
+ d.addCallback(lambda _: self._start_pool(self.DECRYPT_LOOP_PERIOD))
return d
def stop(self):
diff --git a/testing/tests/sync/test_encdecpool.py b/testing/tests/sync/test_encdecpool.py
index 82e99a47..0aa17682 100644
--- a/testing/tests/sync/test_encdecpool.py
+++ b/testing/tests/sync/test_encdecpool.py
@@ -29,7 +29,6 @@ from leap.soledad.client.encdecpool import SyncDecrypterPool
from leap.soledad.common.document import SoledadDocument
from test_soledad.util import BaseSoledadTest
from twisted.internet import defer
-from twisted.test.proto_helpers import MemoryReactorClock
DOC_ID = "mydoc"
DOC_REV = "rev"
@@ -219,9 +218,6 @@ class TestSyncDecrypterPool(BaseSoledadTest):
This test ensures that processing of documents only occur if there is
a sequence in place.
"""
- reactor_clock = MemoryReactorClock()
- self._pool._loop.clock = reactor_clock
-
crypto = self._soledad._crypto
docs = []
@@ -234,18 +230,19 @@ class TestSyncDecrypterPool(BaseSoledadTest):
docs.append((doc, encrypted_content))
# insert the encrypted document in the pool
- self._pool.start(10) # pool is expecting to process 10 docs
+ yield self._pool.start(10) # pool is expecting to process 10 docs
+ self._pool._loop.stop() # we are processing manually
# first three arrives, forming a sequence
for i, (doc, encrypted_content) in enumerate(docs[:3]):
gen = idx = i + 1
yield self._pool.insert_encrypted_received_doc(
doc.doc_id, doc.rev, encrypted_content, gen, "trans_id", idx)
+
# last one arrives alone, so it can't be processed
doc, encrypted_content = docs[-1]
yield self._pool.insert_encrypted_received_doc(
doc.doc_id, doc.rev, encrypted_content, 10, "trans_id", 10)
- reactor_clock.advance(self._pool.DECRYPT_LOOP_PERIOD)
yield self._pool._decrypt_and_recurse()
self.assertEqual(3, self._pool._processed_docs)