[Zodb-checkins] CVS: Zope3/src/zodb/zeo/tests - zeoserver.py:1.7 forker.py:1.4 connection.py:1.4

Jeremy Hylton jeremy@zope.com
Mon, 27 Jan 2003 14:44:19 -0500


Update of /cvs-repository/Zope3/src/zodb/zeo/tests
In directory cvs.zope.org:/tmp/cvs-serv24242/tests

Modified Files:
	zeoserver.py forker.py connection.py 
Log Message:
Explicitly close sockets created inside zeoserver.py.

The change decouples server socket cleanup from general process
cleanup.  It allows the next test server to be created without waiting
for the current process to exit.  On one box (mine) it makes the tests
run about twice as fast.


=== Zope3/src/zodb/zeo/tests/zeoserver.py 1.6 => 1.7 ===
--- Zope3/src/zodb/zeo/tests/zeoserver.py:1.6	Tue Jan 21 11:04:16 2003
+++ Zope3/src/zodb/zeo/tests/zeoserver.py	Mon Jan 27 14:44:14 2003
@@ -66,6 +66,7 @@
 
     def __init__(self, addr, storage, keep):
         self.__super_init()
+        self._sockets = [self]
         self._storage = storage
         self._keep = keep
         # Count down to zero, the number of connects
@@ -98,25 +99,23 @@
             if not self._keep:
                 cleanup(self._storage)
             self.logger.info('exiting')
+            # Close all the other sockets so that we don't have to wait
+            # for os._exit() to get to it before starting the next
+            # server process.
+            for s in self._sockets:
+                s.close()
+            # Now explicitly close the socket returned from accept(),
+            # since it didn't go through the wrapper.
+            sock.close()
             os._exit(0)
         self.logger.info('continuing')
         sock.send('X')
         self._count -= 1
 
-
-class Suicide(threading.Thread):
-    def __init__(self, addr):
-        threading.Thread.__init__(self)
-        self._adminaddr = addr
-
-    def run(self):
-        # If this process doesn't exit in 60 seconds, commit suicide
-        time.sleep(60)
-        from zodb.zeo.tests.forker import shutdown_zeo_server
-        # XXX If the -k option was given to zeoserver, then the process will
-        # go away but the temp files won't get cleaned up.
-        shutdown_zeo_server(self._adminaddr)
-
+    def register_socket(self, sock):
+        # Register a socket to be closed when server shutsdown.
+        self._sockets.append(sock)
+        
 
 def main():
     # Initialize the logging module.
@@ -170,10 +169,7 @@
     addr = ('', zeo_port)
     logger.info('creating the storage server')
     serv = zodb.zeo.server.StorageServer(addr, {'1': storage}, ro_svr)
-    # Create daemon suicide thread
-    d = Suicide(test_addr)
-    d.setDaemon(1)
-    d.start()
+    t.register_socket(serv.dispatcher)
     # Loop for socket events
     logger.info('entering threadedasync loop')
     threadedasync.loop()


=== Zope3/src/zodb/zeo/tests/forker.py 1.3 => 1.4 ===
--- Zope3/src/zodb/zeo/tests/forker.py:1.3	Fri Jan 24 18:20:48 2003
+++ Zope3/src/zodb/zeo/tests/forker.py	Mon Jan 27 14:44:14 2003
@@ -52,7 +52,7 @@
 
 
 def start_zeo_server(conf, addr=None, ro_svr=False, keep=False,
-                     admin_retries=5):
+                     admin_retries=10):
     """Start a ZEO server in a separate process.
 
     Returns the ZEO port, the test server port, and the pid.
@@ -82,18 +82,26 @@
     d['PYTHONPATH'] = os.pathsep.join(sys.path)
     pid = os.spawnve(os.P_NOWAIT, sys.executable, tuple(args), d)
     adminaddr = ('localhost', port+1)
-    # We need to wait until the server starts, but not forever
-    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    # We need to wait until the server starts, but not forever.
+    # Always do a sleep as the first thing, since we don't expect
+    # the spawned process to get started right away.
+    delay = 0.25
     for i in range(admin_retries):
+        time.sleep(delay)
+        logging.debug('forker: connect %s', i)
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         try:
-            logging.debug('forker: connect %s', i)
             s.connect(adminaddr)
             ack = s.recv(1024)
+        except socket.error, e:
+            if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET):
+                raise
+            logging.debug('forker: failed %s' % i)
+            s.close()
+        else:
             logging.debug('forker: acked: %s', ack)
+            s.close()
             break
-        except socket.error, e:
-            if e[0] <> errno.ECONNREFUSED: raise
-            time.sleep(1)
     else:
         logging.debug('forker: boo hoo')
         raise


=== Zope3/src/zodb/zeo/tests/connection.py 1.3 => 1.4 ===
--- Zope3/src/zodb/zeo/tests/connection.py:1.3	Fri Jan 24 18:20:48 2003
+++ Zope3/src/zodb/zeo/tests/connection.py	Mon Jan 27 14:44:14 2003
@@ -120,7 +120,7 @@
     # The start_zeo_server() function attempts to connect to the new
     # server process once a second.  After forker_admin_retries attempts,
     # it fails with an error.
-    forker_admin_retries = 5
+    forker_admin_retries = 10
 
     def startServer(self, create=True, index=0,
                     read_only=False, ro_svr=False, keep=False):
@@ -426,7 +426,7 @@
 
 class ReconnectionTests(CommonSetupTearDown):
     keep = True
-    forker_admin_retries = 10
+    forker_admin_retries = 20
 
     def checkReadOnlyStorage(self):
         # Open a read-only client to a read-only *storage*; stores fail