Merge ~pappacena/launchpad:testfix-librarian-client-race-condition into launchpad:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: befb3673b9ac006563e4f571ae60a7904903e0db
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:testfix-librarian-client-race-condition
Merge into: launchpad:master
Diff against target: 43 lines (+12/-2)
2 files modified
lib/lp/services/librarian/client.py (+2/-1)
lib/lp/services/librarian/tests/test_client.py (+10/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+389162@code.launchpad.net

Commit message

[testfix] Avoiding race condition at librarian client test

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
befb367... by Thiago F. Pappacena

Setting a smaller timeout at test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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:
88 # it will be shared between threads. The easiest way of making this88 # it will be shared between threads. The easiest way of making this
89 # class thread safe is by storing all state in a thread local.89 # class thread safe is by storing all state in a thread local.
90 self.state = threading.local()90 self.state = threading.local()
91 self.state.s_poll_timeout = 0
9192
92 def _connect(self):93 def _connect(self):
93 """Connect this client.94 """Connect this client.
@@ -115,7 +116,7 @@ class FileUploadClient:
115 del self.state.f116 del self.state.f
116117
117 def _checkError(self):118 def _checkError(self):
118 poll_result = self.state.s_poll.poll(0)119 poll_result = self.state.s_poll.poll(self.state.s_poll_timeout)
119 if poll_result:120 if poll_result:
120 fileno, event = poll_result[0]121 fileno, event = poll_result[0]
121 # Accepts any event that contains input data. Even if we122 # 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..3b406c1 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):
252 'librarian', upload_host=upload_host, upload_port=upload_port)252 'librarian', upload_host=upload_host, upload_port=upload_port)
253253
254 client = LibrarianClient()254 client = LibrarianClient()
255255 # Artificially increases timeout to avoid race condition.
256 # The fake server is running in another thread, and we are sure it
257 # will (eventually) reply with an error message. So, let's just wait
258 # until that message arrives.
259 client.state.s_poll_timeout = 120
260
261 # Please, note the mismatch between file size (7) and its actual size
262 # of the content (6). This is intentional, to make sure we are raising
263 # the error coming from the fake server (and not the local check
264 # right after, while uploading the file).
256 self.assertRaisesRegex(265 self.assertRaisesRegex(
257 UploadFailed, 'Server said early: STORE 7 sample.txt',266 UploadFailed, 'Server said early: STORE 7 sample.txt',
258 client.addFile, 'sample.txt', 7, StringIO('sample'), 'text/plain')267 client.addFile, 'sample.txt', 7, StringIO('sample'), 'text/plain')