[Zodb-checkins] CVS: ZODB3/ZEO/tests - forker.py:1.20 testZEO.py:1.48 winserver.py:1.9

Guido van Rossum guido@python.org
Thu, 26 Sep 2002 11:53:17 -0400


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

Modified Files:
	forker.py testZEO.py winserver.py 
Log Message:
Add test framework so we can test the read_only behavior of the
StorageServer as well as that of the storage itself.  Currently the
test fails.


=== ZODB3/ZEO/tests/forker.py 1.19 => 1.20 ===
--- ZODB3/ZEO/tests/forker.py:1.19	Fri Sep 13 15:35:02 2002
+++ ZODB3/ZEO/tests/forker.py	Thu Sep 26 11:53:17 2002
@@ -50,7 +50,7 @@
 
 if os.name == "nt":
 
-    def start_zeo_server(storage_name, args, addr=None):
+    def start_zeo_server(storage_name, args, addr=None, ro_svr=0):
         """Start a ZEO server in a separate process.
 
         Returns the ZEO port, the test server port, and the pid.
@@ -63,7 +63,11 @@
         script = ZEO.tests.winserver.__file__
         if script.endswith('.pyc'):
             script = script[:-1]
-        args = (sys.executable, script, str(port), storage_name) + args
+        if ro_svr:
+            args = (sys.executable, script, "-r")
+        else:
+            args = (sys.executable, script)
+        args += (str(port), storage_name) + args
         d = os.environ.copy()
         d['PYTHONPATH'] = os.pathsep.join(sys.path)
         pid = os.spawnve(os.P_NOWAIT, sys.executable, args, d)
@@ -103,7 +107,7 @@
             except os.error:
                 pass
 
-    def start_zeo_server(storage_name, args, addr):
+    def start_zeo_server(storage_name, args, addr, ro_svr=0):
         assert isinstance(args, types.TupleType)
         rd, wr = os.pipe()
         pid = os.fork()
@@ -114,11 +118,12 @@
             try:
                 if PROFILE:
                     p = hotshot.Profile("stats.s.%d" % os.getpid())
-                    p.runctx("run_server(addr, rd, wr, storage_name, args)",
-                             globals(), locals())
+                    p.runctx(
+                        "run_server(addr, rd, wr, storage_name, args, ro_svr)",
+                        globals(), locals())
                     p.close()
                 else:
-                    run_server(addr, rd, wr, storage_name, args)
+                    run_server(addr, rd, wr, storage_name, args, ro_svr)
             except:
                 print "Exception in ZEO server process"
                 traceback.print_exc()
@@ -133,14 +138,14 @@
         klass = getattr(mod, name)
         return klass(*args)
 
-    def run_server(addr, rd, wr, storage_name, args):
+    def run_server(addr, rd, wr, storage_name, args, ro_svr):
         # in the child, run the storage server
         global server
         os.close(wr)
         ZEOServerExit(rd)
         import ZEO.StorageServer, ZEO.zrpc.server
         storage = load_storage(storage_name, args)
-        server = ZEO.StorageServer.StorageServer(addr, {'1':storage})
+        server = ZEO.StorageServer.StorageServer(addr, {'1':storage}, ro_svr)
         ZEO.zrpc.server.loop()
         storage.close()
         if isinstance(addr, types.StringType):


=== ZODB3/ZEO/tests/testZEO.py 1.47 => 1.48 ===
--- ZODB3/ZEO/tests/testZEO.py:1.47	Fri Sep 20 13:37:34 2002
+++ ZODB3/ZEO/tests/testZEO.py	Thu Sep 26 11:53:17 2002
@@ -357,8 +357,8 @@
         # Stores should succeed here
         self._dostore()
 
-    def checkReadOnlyFallbackReadOnly(self):
-        # Open a fallback client to a read-only server; stores fail
+    def checkReadOnlyFallbackReadOnlyStorage(self):
+        # Open a fallback client to a read-only *storage*; stores fail
 
         # We don't want the read-write server created by setUp()
         self.shutdownServer()
@@ -372,6 +372,21 @@
         # Stores should fail here
         self.assertRaises(ReadOnlyError, self._dostore)
 
+    def checkReadOnlyFallbackReadOnlyServer(self):
+        # Open a fallback client to a read-only *server*; stores fail
+
+        # We don't want the read-write server created by setUp()
+        self.shutdownServer()
+        self._servers = []
+        self._pids = []
+
+        # Start a read-only server
+        self._startServer(create=0, index=0, ro_svr=1)
+        # Start a read-only-fallback client
+        self._storage = self.openClientStorage(wait=0, read_only_fallback=1)
+        # Stores should fail here
+        self.assertRaises(ReadOnlyError, self._dostore)
+
     # XXX Compare checkReconnectXXX() here to checkReconnection()
     # further down.  Is the code here hopelessly naive, or is
     # checkReconnection() overwrought?
@@ -604,14 +619,14 @@
 
 class UnixConnectionTests(ConnectionTests):
 
-    def _startServer(self, create=1, index=0, read_only=0):
+    def _startServer(self, create=1, index=0, read_only=0, ro_svr=0):
         zLOG.LOG("testZEO", zLOG.INFO,
                  "_startServer(create=%d, index=%d, read_only=%d)" %
                  (create, index, read_only))
         path = "%s.%d" % (self.file, index)
         addr = self.addr[index]
-        pid, server = forker.start_zeo_server('FileStorage',
-                                              (path, create, read_only), addr)
+        pid, server = forker.start_zeo_server(
+            'FileStorage', (path, create, read_only), addr, ro_svr)
         self._pids.append(pid)
         self._servers.append(server)
 
@@ -627,7 +642,7 @@
 
 class WindowsConnectionTests(ConnectionTests):
 
-    def _startServer(self, create=1, index=0, read_only=0):
+    def _startServer(self, create=1, index=0, read_only=0, ro_svr=0):
         zLOG.LOG("testZEO", zLOG.INFO,
                  "_startServer(create=%d, index=%d, read_only=%d)" %
                  (create, index, read_only))
@@ -635,7 +650,7 @@
         addr = self.addr[index]
         args = (path, '='+str(create), '='+str(read_only))
         _addr, test_addr, test_pid = forker.start_zeo_server(
-            'FileStorage', args, addr)
+            'FileStorage', args, addr, ro_svr)
         self._pids.append(test_pid)
         self._servers.append(test_addr)
 


=== ZODB3/ZEO/tests/winserver.py 1.8 => 1.9 ===
--- ZODB3/ZEO/tests/winserver.py:1.8	Wed Sep 18 21:55:45 2002
+++ ZODB3/ZEO/tests/winserver.py	Thu Sep 26 11:53:17 2002
@@ -50,7 +50,12 @@
     mod = getattr(package, name)
     return getattr(mod, name)
 
-def main(port, storage_name, rawargs):
+def main(args):
+    ro_svr = 0
+    if args[0] == "-r":
+        ro_svr = 1
+        del args[0]
+    port, storage_name, rawargs = args
     klass = load_storage_class(storage_name)
     args = []
     for arg in rawargs:
@@ -61,7 +66,8 @@
     zeo_port = int(port)
     test_port = zeo_port + 1
     t = ZEOTestServer(('', test_port), storage)
-    serv = ZEO.StorageServer.StorageServer(('', zeo_port), {'1': storage})
+    addr = [('', zeo_port)]
+    serv = ZEO.StorageServer.StorageServer(addr, {'1': storage}, ro_svr)
     import zLOG
     label = "winserver:%d" % os.getpid()
     while asyncore.socket_map:
@@ -70,5 +76,4 @@
 
 if __name__ == "__main__":
     import sys
-
-    main(sys.argv[1], sys.argv[2], sys.argv[3:])
+    main(sys.argv[1:])