Rev 4891: Fix a hang in the bundle tests. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-all-reconnect-819604

John Arbash Meinel john at arbash-meinel.com
Wed Sep 12 09:26:57 UTC 2012


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-all-reconnect-819604

------------------------------------------------------------
revno: 4891
revision-id: john at arbash-meinel.com-20120912092637-7kop15ivhav2jh3y
parent: john at arbash-meinel.com-20120912082718-rc0056el65dtvpdy
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-all-reconnect-819604
timestamp: Wed 2012-09-12 13:26:37 +0400
message:
  Fix a hang in the bundle tests.
  
  The dummy server we implemented only allowed a single connection, and then it
  would leave the main socket in 'listen' without ever calling accept again.
  If we close it early, then we get ConnectionError instead of ConnectionReset
  and we were trynig to test Reset.
  So we just loop on the connect.
  In bzr-2.5 it is done differently because we have the very nice test_server
  infrastructure.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_bundle.py'
--- a/bzrlib/tests/test_bundle.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/tests/test_bundle.py	2012-09-12 09:26:37 +0000
@@ -1855,20 +1855,23 @@
         self.sock.bind(('127.0.0.1', 0))
         self.sock.listen(1)
         self.port = self.sock.getsockname()[1]
+        self.stopping = threading.Event()
         self.thread = threading.Thread(
             name='%s (port %d)' % (self.__class__.__name__, self.port),
             target=self.accept_and_close)
         self.thread.start()
 
     def accept_and_close(self):
-        conn, addr = self.sock.accept()
-        conn.shutdown(socket.SHUT_RDWR)
-        conn.close()
+        while not self.stopping.isSet():
+            conn, addr = self.sock.accept()
+            conn.shutdown(socket.SHUT_RDWR)
+            conn.close()
 
     def get_url(self):
         return 'bzr://127.0.0.1:%d/' % (self.port,)
 
     def stop_server(self):
+        self.stopping.set()
         try:
             # make sure the thread dies by connecting to the listening socket,
             # just in case the test failed to do so.



More information about the bazaar-commits mailing list