← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:testfix-close-connections into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:testfix-close-connections into launchpad:master.

Commit message:
[testfix] Avoiding to close fake librarian server connection too soon on test code

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/388582
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:testfix-close-connections into launchpad:master.
diff --git a/lib/lp/services/librarian/client.py b/lib/lp/services/librarian/client.py
index 877e51c..3a32abe 100644
--- a/lib/lp/services/librarian/client.py
+++ b/lib/lp/services/librarian/client.py
@@ -118,8 +118,8 @@ class FileUploadClient:
         poll_result = self.state.s_poll.poll(0)
         if poll_result:
             fileno, event = poll_result[0]
-            assert fileno == self.state.s.fileno()
-            assert event == select.EPOLLIN
+            if fileno != self.state.s.fileno() or event != select.EPOLLIN:
+                return
             response = six.ensure_str(
                 self.state.f.readline().strip(), errors='replace')
             raise UploadFailed('Server said early: ' + response)
diff --git a/lib/lp/services/librarian/tests/test_client.py b/lib/lp/services/librarian/tests/test_client.py
index 750c21e..34dce5f 100644
--- a/lib/lp/services/librarian/tests/test_client.py
+++ b/lib/lp/services/librarian/tests/test_client.py
@@ -179,6 +179,7 @@ class EchoServer(threading.Thread):
         self.socket.settimeout(1)
         self.socket.bind(('localhost', 0))
         self.socket.listen(1)
+        self.connections = []
 
     def join(self, *args, **kwargs):
         self.should_stop = True
@@ -188,14 +189,17 @@ class EchoServer(threading.Thread):
         while not self.should_stop:
             try:
                 conn, addr = self.socket.accept()
+                self.connections.append(conn)
                 data = conn.recv(1024)
                 conn.sendall(data)
-                conn.close()
             except socket.timeout:
                 # We use the timeout to control how much time we will wait
                 # to check again if self.should_stop was set, and the thread
                 # will join.
                 pass
+        for conn in self.connections:
+            conn.close()
+        self.connections = []
         self.socket.close()