[Zodb-checkins] CVS: ZODB3/ZEO/tests - zeoserver.py:1.15 testConnection.py:1.13 forker.py:1.36 ConnectionTests.py:1.24

Jeremy Hylton jeremy at zope.com
Thu May 29 15:26:57 EDT 2003


Update of /cvs-repository/ZODB3/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv31469/ZEO/tests

Modified Files:
	zeoserver.py testConnection.py forker.py ConnectionTests.py 
Log Message:
Revise the test framework to use ZConfig instead of a custom argv.


=== ZODB3/ZEO/tests/zeoserver.py 1.14 => 1.15 ===
--- ZODB3/ZEO/tests/zeoserver.py:1.14	Fri May 23 17:33:29 2003
+++ ZODB3/ZEO/tests/zeoserver.py	Thu May 29 14:26:56 2003
@@ -27,6 +27,7 @@
 import ZConfig.Context
 import zLOG
 import ZEO.StorageServer
+from ZEO.runzeo import ZEOOptions
 from ZODB.config import storageFromURL
 
 
@@ -134,54 +135,49 @@
 def main():
     label = 'zeoserver:%d' % os.getpid()
     log(label, 'starting')
+    
     # We don't do much sanity checking of the arguments, since if we get it
     # wrong, it's a bug in the test suite.
-    ro_svr = 0
     keep = 0
     configfile = None
-    invalidation_queue_size = 100
-    transaction_timeout = None
-    monitor_address = None
     # Parse the arguments and let getopt.error percolate
-    opts, args = getopt.getopt(sys.argv[1:], 'rkC:Q:T:m:')
+    opts, args = getopt.getopt(sys.argv[1:], 'kC:')
     for opt, arg in opts:
-        if opt == '-r':
-            ro_svr = 1
-        elif opt == '-k':
+        if opt == '-k':
             keep = 1
         elif opt == '-C':
             configfile = arg
-        elif opt == '-Q':
-            invalidation_queue_size = int(arg)
-        elif opt == '-T':
-            transaction_timeout = int(arg)
-        elif opt == "-m":
-            monitor_address = '', int(arg)
+
+    zo = ZEOOptions()
+    zo.realize(["-C", configfile])
+    zeo_port = int(zo.address[1])
+            
     # Open the config file and let ZConfig parse the data there.  Then remove
     # the config file, otherwise we'll leave turds.
-    storage = storageFromURL(configfile)
-    os.remove(configfile)
     # The rest of the args are hostname, portnum
-    zeo_port = int(args[0])
     test_port = zeo_port + 1
     test_addr = ('localhost', test_port)
     addr = ('localhost', zeo_port)
     log(label, 'creating the storage server')
-    serv = ZEO.StorageServer.StorageServer(
-        addr, {'1': storage}, ro_svr,
-        invalidation_queue_size=invalidation_queue_size,
-        transaction_timeout=transaction_timeout,
-        monitor_address=monitor_address)
+    server = ZEO.StorageServer.StorageServer(
+        zo.address,
+        {"1": zo.storages[0].open()},
+        read_only=zo.read_only,
+        invalidation_queue_size=zo.invalidation_queue_size,
+        transaction_timeout=zo.transaction_timeout,
+        monitor_address=zo.monitor_address)
+    
     try:
-        log(label, 'creating the test server, ro: %s, keep: %s', ro_svr, keep)
-        t = ZEOTestServer(test_addr, serv, keep)
+        log(label, 'creating the test server, keep: %s', keep)
+        t = ZEOTestServer(test_addr, server, keep)
     except socket.error, e:
         if e[0] <> errno.EADDRINUSE: raise
         log(label, 'addr in use, closing and exiting')
         storage.close()
         cleanup(storage)
         sys.exit(2)
-    t.register_socket(serv.dispatcher)
+        
+    t.register_socket(server.dispatcher)
     # Create daemon suicide thread
     d = Suicide(test_addr)
     d.setDaemon(1)


=== ZODB3/ZEO/tests/testConnection.py 1.12 => 1.13 ===
--- ZODB3/ZEO/tests/testConnection.py:1.12	Fri May 23 17:45:11 2003
+++ ZODB3/ZEO/tests/testConnection.py	Thu May 29 14:26:56 2003
@@ -26,7 +26,7 @@
 class FileStorageConfig:
     def getConfig(self, path, create, read_only):
         return """\
-        <filestorage>
+        <filestorage 1>
         path %s
         create %s
         read-only %s
@@ -37,14 +37,14 @@
 class BerkeleyStorageConfig:
     def getConfig(self, path, create, read_only):
         return """\
-        <fullstorage>
+        <fullstorage 1>
         name %s
         read-only %s
         </fullstorage>""" % (path, read_only and "yes" or "no")
 
 class MappingStorageConfig:
     def getConfig(self, path, create, read_only):
-        return """<mappingstorage/>"""
+        return """<mappingstorage 1/>"""
 
 
 class FileStorageConnectionTests(


=== ZODB3/ZEO/tests/forker.py 1.35 => 1.36 ===
--- ZODB3/ZEO/tests/forker.py:1.35	Thu May 29 12:51:34 2003
+++ ZODB3/ZEO/tests/forker.py	Thu May 29 14:26:56 2003
@@ -19,70 +19,80 @@
 import errno
 import random
 import socket
+import StringIO
 import tempfile
 
 import zLOG
 
-def get_port():
-    """Return a port that is not in use.
+class ZEOConfig:
+    """Class to generate ZEO configuration file. """
 
-    Checks if a port is in use by trying to connect to it.  Assumes it
-    is not in use if connect raises an exception.
+    def __init__(self, addr):
+        self.address = addr
+        self.read_only = None
+        self.invalidation_queue_size = None
+        self.monitor_address = None
+        self.transaction_timeout = None
+        self.authentication_protocol = None
+        self.authentication_database = None
+        self.authentication_realm = None
+
+    def dump(self, f):
+        print >> f, "<zeo>"
+        print >> f, "address %s:%s" % self.address
+        if self.read_only is not None:
+            print >> f, "read-only", self.read_only and "true" or "false"
+        if self.invalidation_queue_size is not None:
+            print >> f, "invalidation-queue-size", self.invalidation_queue_size
+        if self.monitor_address is not None:
+            print >> f, "monitor-address", self.monitor_address
+        if self.transaction_timeout is not None:
+            print >> f, "transaction-timeout", self.transaction_timeout
+        if self.authentication_protocol is not None:
+            print >> f, "authentication-protocol", self.authentication_protocol
+        if self.authentication_database is not None:
+            print >> f, "authentication-database", self.authentication_database
+        if self.authentication_realm is not None:
+            print >> f, "authentication-realm", self.authentication_realm
+        print >> f, "</zeo>"
+
+    def __str__(self):
+        f = StringIO.StringIO()
+        self.dump(f)
+        return f.getvalue()
 
-    Raises RuntimeError after 10 tries.
-    """
-    for i in range(10):
-        port = random.randrange(20000, 30000)
-        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        try:
-            try:
-                s.connect(('localhost', port))
-            except socket.error:
-                # XXX check value of error?
-                return port
-        finally:
-            s.close()
-    raise RuntimeError, "Can't find port"
-
-def start_zeo_server(conf, addr=None, ro_svr=0, monitor=0, keep=0, invq=None,
-                     timeout=None):
+def start_zeo_server(storage_conf, zeo_conf, port, keep=0):
     """Start a ZEO server in a separate process.
 
-    Returns the ZEO port, the test server port, and the pid.
+    Takes two positional arguments a string containing the storage conf
+    and a ZEOConfig object.
+
+    Returns the ZEO port, the test server port, the pid, and the path
+    to the config file.
     """
+    
     # Store the config info in a temp file.
-    tmpfile = tempfile.mktemp()
+    tmpfile = tempfile.mktemp(".conf")
     fp = open(tmpfile, 'w')
-    fp.write(conf)
+    zeo_conf.dump(fp)
+    fp.write(storage_conf)
     fp.close()
-    # Create the server
+    
+    # Find the zeoserver script
     import ZEO.tests.zeoserver
-    if addr is None:
-        port = get_port()
-    else:
-        port = addr[1]
     script = ZEO.tests.zeoserver.__file__
     if script.endswith('.pyc'):
         script = script[:-1]
+        
     # Create a list of arguments, which we'll tuplify below
     qa = _quote_arg
     args = [qa(sys.executable), qa(script), '-C', qa(tmpfile)]
-    if ro_svr:
-        args.append('-r')
     if keep:
-        args.append('-k')
-    if invq:
-        args += ['-Q', str(invq)]
-    if timeout:
-        args += ['-T', str(timeout)]
-    if monitor:
-        # XXX Is it safe to reuse the port?
-        args += ['-m', '42000']
-    args.append(str(port))
+        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)
-    adminaddr = ('localhost', port+1)
+    adminaddr = ('localhost', port + 1)
     # We need to wait until the server starts, but not forever
     for i in range(20):
         time.sleep(0.25)
@@ -101,7 +111,7 @@
     else:
         zLOG.LOG('forker', zLOG.DEBUG, 'boo hoo')
         raise
-    return ('localhost', port), adminaddr, pid
+    return ('localhost', port), adminaddr, pid, tmpfile
 
 
 if sys.platform[:3].lower() == "win":


=== ZODB3/ZEO/tests/ConnectionTests.py 1.23 => 1.24 ===
--- ZODB3/ZEO/tests/ConnectionTests.py:1.23	Tue Apr 29 15:42:45 2003
+++ ZODB3/ZEO/tests/ConnectionTests.py	Thu May 29 14:26:56 2003
@@ -77,12 +77,15 @@
         self.addr = []
         self._pids = []
         self._servers = []
+        self.conf_path = None
         self._newAddr()
         self.startServer()
 
     def tearDown(self):
         """Try to cause the tests to halt"""
         zLOG.LOG("testZEO", zLOG.INFO, "tearDown() %s" % self.id())
+        if self.conf_path:
+            os.remove(self.conf_path)
         if getattr(self, '_storage', None) is not None:
             self._storage.close()
             if hasattr(self._storage, 'cleanup'):
@@ -132,10 +135,20 @@
                  "startServer(create=%d, index=%d, read_only=%d) @ %s" %
                  (create, index, read_only, addr))
         path = "%s.%d" % (self.file, index)
-        conf = self.getConfig(path, create, read_only)
-        zeoport, adminaddr, pid = forker.start_zeo_server(
-            conf, addr, ro_svr,
-            self.monitor, self.keep, self.invq, self.timeout)
+        sconf = self.getConfig(path, create, read_only)
+        zconf = forker.ZEOConfig(addr)
+        if ro_svr:
+            zconf.read_only = 1
+        if self.monitor:
+            zconf.monitor_address = monitor
+        if self.invq:
+            zconf.invalidation_queue_size = self.invq
+        if self.timeout:
+            zconf.transaction_timeout = self.timeout
+        zeoport, adminaddr, pid, path = forker.start_zeo_server(sconf, zconf,
+                                                                addr[1],
+                                                                self.keep)
+        self.conf_path = path
         self._pids.append(pid)
         self._servers.append(adminaddr)
 




More information about the Zodb-checkins mailing list