launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25154
[Merge] ~pappacena/launchpad:testfix-librarian-client-race-condition into launchpad:master
Thiago F. Pappacena has proposed merging ~pappacena/launchpad:testfix-librarian-client-race-condition into launchpad:master.
Commit message:
[testfix] Avoiding race condition at librarian client test
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/389162
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:testfix-librarian-client-race-condition into launchpad:master.
diff --git a/lib/lp/services/librarian/client.py b/lib/lp/services/librarian/client.py
index 737d9e4..ba18805 100644
--- a/lib/lp/services/librarian/client.py
+++ b/lib/lp/services/librarian/client.py
@@ -88,6 +88,7 @@ class FileUploadClient:
# it will be shared between threads. The easiest way of making this
# class thread safe is by storing all state in a thread local.
self.state = threading.local()
+ self.state.s_poll_timeout = 0
def _connect(self):
"""Connect this client.
@@ -115,7 +116,7 @@ class FileUploadClient:
del self.state.f
def _checkError(self):
- poll_result = self.state.s_poll.poll(0)
+ poll_result = self.state.s_poll.poll(self.state.s_poll_timeout)
if poll_result:
fileno, event = poll_result[0]
# Accepts any event that contains input data. Even if we
diff --git a/lib/lp/services/librarian/tests/test_client.py b/lib/lp/services/librarian/tests/test_client.py
index 34dce5f..fe20af3 100644
--- a/lib/lp/services/librarian/tests/test_client.py
+++ b/lib/lp/services/librarian/tests/test_client.py
@@ -252,7 +252,16 @@ class LibrarianClientTestCase(TestCase):
'librarian', upload_host=upload_host, upload_port=upload_port)
client = LibrarianClient()
-
+ # Artificially increases timeout to avoid race condition.
+ # The fake server is running in another thread, and we are sure it
+ # will (eventually) reply with an error message. So, let's just wait
+ # until that message arrives.
+ client.state.s_poll_timeout = -1
+
+ # Please, note the mismatch between file size (7) and its actual size
+ # of the content (6). This is intentional, to make sure we are raising
+ # the error coming from the fake server (and not the local check
+ # right after, while uploading the file).
self.assertRaisesRegex(
UploadFailed, 'Server said early: STORE 7 sample.txt',
client.addFile, 'sample.txt', 7, StringIO('sample'), 'text/plain')