[Zodb-checkins] SVN: ZODB/trunk/src/ZEO/tests/forker.py Switched to using the subprocess module so that the zeo server closes

Jim Fulton jim at zope.com
Tue Nov 18 20:45:08 EST 2008


Log message for revision 93120:
  Switched to using the subprocess module so that the zeo server closes
  all but the standard file descriptors.  This fixed a really hard to
  debug test failure. (A server started after a client storage was
  started had the client storage's cache loc file open, preventing the
  client storage from being reopened.)
  
  For starting servers, the storage config not defaults to a simple
  file-storage configuration.
  
  Use a simple log file configuration for the storage server rather than
  trying to somehow copy the useless test log configuration. This makes
  it far more likely that there will be a sever log available when
  debugging test failures.
  

Changed:
  U   ZODB/trunk/src/ZEO/tests/forker.py

-=-
Modified: ZODB/trunk/src/ZEO/tests/forker.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/forker.py	2008-11-19 01:45:05 UTC (rev 93119)
+++ ZODB/trunk/src/ZEO/tests/forker.py	2008-11-19 01:45:07 UTC (rev 93120)
@@ -19,6 +19,7 @@
 import time
 import errno
 import socket
+import subprocess
 import logging
 import StringIO
 import tempfile
@@ -60,39 +61,14 @@
             print >> f, "authentication-realm", self.authentication_realm
         print >> f, "</zeo>"
 
-        logger = logging.getLogger()
-        print >> f
-        print >> f, "<eventlog>"
-        print >> f, "level", logger.level
-        for handler in logger.handlers:
-            if isinstance(handler, logging.FileHandler):
-                path = handler.baseFilename
-            elif isinstance(handler, logging.StreamHandler):
-                stream = handler.stream
-                if stream.name == "<stdout>":
-                    path = "STDOUT"
-                elif stream.name == "<stderr>":
-                    path = "STDERR"
-                else:
-                    # just drop it on the floor; unlikely an issue when testing
-                    continue
-            else:
-                # just drop it on the floor; unlikely an issue when testing
-                continue
-            # This doesn't convert the level values to names, so the
-            # generated configuration isn't as nice as it could be,
-            # but it doesn't really need to be.
-            print >> f, "<logfile>"
-            print >> f, "level", handler.level
-            print >> f, "path ", path
-            if handler.formatter:
-                formatter = handler.formatter
-                if formatter._fmt:
-                    print >> f, "format", encode_format(formatter._fmt)
-                if formatter.datefmt:
-                    print >> f, "dateformat", encode_format(formatter.datefmt)
-            print >> f, "</logfile>"
-        print >> f, "</eventlog>"
+        print >> f, """
+        <eventlog>
+          level INFO
+          <logfile>
+             path server-%s.log
+          </logfile>
+        </eventlog>
+        """ % self.address[1]
 
     def __str__(self):
         f = StringIO.StringIO()
@@ -109,7 +85,8 @@
     return fmt
 
 
-def start_zeo_server(storage_conf, zeo_conf=None, port=None, keep=False):
+def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
+                     path='Data.fs'):
     """Start a ZEO server in a separate process.
 
     Takes two positional arguments a string containing the storage conf
@@ -119,6 +96,9 @@
     to the config file.
     """
 
+    if not storage_conf:
+        storage_conf = '<filestorage>\npath %s\n</filestorage>' % path
+
     if port is None:
         raise AssertionError("The port wasn't specified")
 
@@ -148,7 +128,9 @@
         args.append("-k")
     d = os.environ.copy()
     d['PYTHONPATH'] = os.pathsep.join(sys.path)
-    pid = os.spawnve(os.P_NOWAIT, sys.executable, tuple(args), d)
+
+    pid = subprocess.Popen(args, env=d, close_fds=True).pid
+
     adminaddr = ('localhost', port + 1)
     # We need to wait until the server starts, but not forever.
     # 30 seconds is a somewhat arbitrary upper bound.  A BDBStorage
@@ -292,7 +274,7 @@
 
     servers = []
 
-    def start_server(storage_conf, zeo_conf=None, port=None, keep=False,
+    def start_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
                      addr=None):
         """Start a ZEO server.
 



More information about the Zodb-checkins mailing list