[Zope3-checkins] SVN: Zope3/trunk/src/zope/server/ Allow old asyncore connections to close before testing.

Shane Hathaway shane at zope.com
Fri Sep 3 04:06:17 EDT 2004


Log message for revision 27440:
  Allow old asyncore connections to close before testing.
  
  This seems to fix the spurious messages about leaking sockets.  However, 
  other tests shouldn't be leaving open sockets around.
  


Changed:
  U   Zope3/trunk/src/zope/server/ftp/tests/test_ftpserver.py
  U   Zope3/trunk/src/zope/server/http/tests/test_httpserver.py


-=-
Modified: Zope3/trunk/src/zope/server/ftp/tests/test_ftpserver.py
===================================================================
--- Zope3/trunk/src/zope/server/ftp/tests/test_ftpserver.py	2004-09-03 06:47:45 UTC (rev 27439)
+++ Zope3/trunk/src/zope/server/ftp/tests/test_ftpserver.py	2004-09-03 08:06:17 UTC (rev 27440)
@@ -54,6 +54,10 @@
 
     def setUp(self):
         td.setThreadCount(1)
+        if len(asyncore.socket_map) != 1:
+            # Let sockets die off.
+            # XXX tests should be more careful to clear the socket map.
+            asyncore.poll(0.1)
         self.orig_map_size = len(asyncore.socket_map)
         self.hook_asyncore_error()
 

Modified: Zope3/trunk/src/zope/server/http/tests/test_httpserver.py
===================================================================
--- Zope3/trunk/src/zope/server/http/tests/test_httpserver.py	2004-09-03 06:47:45 UTC (rev 27439)
+++ Zope3/trunk/src/zope/server/http/tests/test_httpserver.py	2004-09-03 08:06:17 UTC (rev 27440)
@@ -19,7 +19,7 @@
 from asyncore import socket_map, poll
 import socket
 
-from threading import Thread
+from threading import Thread, Event
 from zope.server.taskthreads import ThreadedTaskDispatcher
 from zope.server.http.httpserver import HTTPServer
 from zope.server.adjustments import Adjustments
@@ -78,6 +78,10 @@
 
     def setUp(self):
         td.setThreadCount(4)
+        if len(socket_map) != 1:
+            # Let sockets die off.
+            # XXX tests should be more careful to clear the socket map.
+            asyncore.poll(0.1)
         self.orig_map_size = len(socket_map)
         self.hook_asyncore_error()
         self.server = EchoHTTPServer(LOCALHOST, SERVER_PORT,
@@ -88,9 +92,11 @@
             self.port = CONNECT_TO_PORT
         self.run_loop = 1
         self.counter = 0
+        self.thread_started = Event()
         self.thread = Thread(target=self.loop)
         self.thread.start()
-        sleep(0.1)  # Give the thread some time to start.
+        self.thread_started.wait(10.0)
+        self.assert_(self.thread_started.isSet())
 
     def tearDown(self):
         self.run_loop = 0
@@ -109,6 +115,7 @@
         self.unhook_asyncore_error()
 
     def loop(self):
+        self.thread_started.set()
         while self.run_loop:
             self.counter = self.counter + 1
             #print 'loop', self.counter



More information about the Zope3-Checkins mailing list