[Zodb-checkins] CVS: ZODB3/ZEO/tests - ConnectionTests.py:1.4.2.3 forker.py:1.21.2.1 testConnection.py:1.1.2.2

Guido van Rossum guido@python.org
Mon, 20 Jan 2003 16:54:32 -0500


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

Modified Files:
      Tag: ZODB3-3_1-branch
	ConnectionTests.py forker.py testConnection.py 
Log Message:
Sneak a new feature in the ZODB 3.1.1 release branch: transaction
timeouts.  This is a backport of the same feature in ZODB 3.2.

Why backport a feature?  We absolutely need this for a customer
project that's stuck on ZODB 3.1.x indefinitely; maintaining a brach
off the 3.1.1 release branch indefinitely would be a branching
nightmare.  The feature is not enabled by default, and when not
enabled it doesn't change anything.  So this should be safe.


=== ZODB3/ZEO/tests/ConnectionTests.py 1.4.2.2 => 1.4.2.3 ===
--- ZODB3/ZEO/tests/ConnectionTests.py:1.4.2.2	Mon Jan 20 16:01:03 2003
+++ ZODB3/ZEO/tests/ConnectionTests.py	Mon Jan 20 16:54:28 2003
@@ -86,7 +86,8 @@
     def shutdownServer(self, index=0):
         raise NotImplementedError
 
-    def startServer(self, create=1, index=0, read_only=0, ro_svr=0):
+    def startServer(self, create=1, index=0, read_only=0, ro_svr=0,
+                    transaction_timeout=None):
         raise NotImplementedError
 
     def tearDown(self):
@@ -545,3 +546,30 @@
 
         self._storage = self.openClientStorage()
         self._dostore()
+
+    def checkTimeout(self):
+        self.shutdownServer()
+        self.startServer(transaction_timeout=1)
+        self._storage = storage = self.openClientStorage()
+        txn = Transaction()
+        storage.tpc_begin(txn)
+        storage.tpc_vote(txn)
+        time.sleep(2)
+        self.assertRaises(Disconnected, storage.tpc_finish, txn)
+
+    def checkTimeoutOnAbort(self):
+        self.shutdownServer()
+        self.startServer(transaction_timeout=1)
+        self._storage = storage = self.openClientStorage()
+        txn = Transaction()
+        storage.tpc_begin(txn)
+        storage.tpc_vote(txn)
+        storage.tpc_abort(txn)
+
+    def checkTimeoutOnAbortNoLock(self):
+        self.shutdownServer()
+        self.startServer(transaction_timeout=1)
+        self._storage = storage = self.openClientStorage()
+        txn = Transaction()
+        storage.tpc_begin(txn)
+        storage.tpc_abort(txn)


=== ZODB3/ZEO/tests/forker.py 1.21 => 1.21.2.1 ===
--- ZODB3/ZEO/tests/forker.py:1.21	Thu Sep 26 12:13:45 2002
+++ ZODB3/ZEO/tests/forker.py	Mon Jan 20 16:54:28 2003
@@ -22,11 +22,6 @@
 import types
 import ZEO.ClientStorage
 
-# Change value of PROFILE to enable server-side profiling
-PROFILE = 0
-if PROFILE:
-    import hotshot
-
 def get_port():
     """Return a port that is not in use.
 
@@ -50,7 +45,9 @@
 
 if os.name == "nt":
 
-    def start_zeo_server(storage_name, args, addr=None, ro_svr=0):
+    def start_zeo_server(storage_name, args, addr=None, ro_svr=0,
+                         transaction_timeout=None):
+                         # XXX transaction_timeout is not passed on here
         """Start a ZEO server in a separate process.
 
         Returns the ZEO port, the test server port, and the pid.
@@ -107,7 +104,8 @@
             except os.error:
                 pass
 
-    def start_zeo_server(storage_name, args, addr, ro_svr=0):
+    def start_zeo_server(storage_name, args, addr, ro_svr=0,
+                         transaction_timeout=None):
         assert isinstance(args, types.TupleType)
         rd, wr = os.pipe()
         pid = os.fork()
@@ -116,14 +114,8 @@
             import ZEO.zrpc.log
             reload(ZEO.zrpc.log) # Don't share the logging file object
             try:
-                if PROFILE:
-                    p = hotshot.Profile("stats.s.%d" % os.getpid())
-                    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, ro_svr)
+                run_server(addr, rd, wr, storage_name, args, ro_svr,
+                           transaction_timeout=transaction_timeout)
             except:
                 print "Exception in ZEO server process"
                 traceback.print_exc()
@@ -138,21 +130,24 @@
         klass = getattr(mod, name)
         return klass(*args)
 
-    def run_server(addr, rd, wr, storage_name, args, ro_svr):
+    def run_server(addr, rd, wr, storage_name, args, ro_svr,
+                   transaction_timeout=None):
         # 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}, ro_svr)
+        server = ZEO.StorageServer.StorageServer(addr, {'1':storage}, ro_svr,
+                                                 transaction_timeout)
         ZEO.zrpc.server.loop()
         storage.close()
         if isinstance(addr, types.StringType):
             os.unlink(addr)
 
     def start_zeo(storage_name, args, cache=None, cleanup=None,
-                  domain="AF_INET", storage_id="1", cache_size=20000000):
+                  domain="AF_INET", storage_id="1", cache_size=20000000,
+                  transaction_timeout=None):
         """Setup ZEO client-server for storage.
 
         Returns a ClientStorage instance and a ZEOClientExit instance.
@@ -168,7 +163,8 @@
         else:
             raise ValueError, "bad domain: %s" % domain
 
-        pid, exit = start_zeo_server(storage_name, args, addr)
+        pid, exit = start_zeo_server(storage_name, args, addr,
+                                     transaction_timeout=transaction_timeout)
         s = ZEO.ClientStorage.ClientStorage(addr, storage_id,
                                             client=cache,
                                             cache_size=cache_size,


=== ZODB3/ZEO/tests/testConnection.py 1.1.2.1 => 1.1.2.2 ===
--- ZODB3/ZEO/tests/testConnection.py:1.1.2.1	Thu Oct  3 20:09:05 2002
+++ ZODB3/ZEO/tests/testConnection.py	Mon Jan 20 16:54:28 2003
@@ -36,14 +36,17 @@
 
     """Add Unix-specific scaffolding to the generic test suite."""
 
-    def startServer(self, create=1, index=0, read_only=0, ro_svr=0):
+    def startServer(self, create=1, index=0, read_only=0, ro_svr=0,
+                    transaction_timeout=None):
         zLOG.LOG("testZEO", zLOG.INFO,
-                 "startServer(create=%d, index=%d, read_only=%d)" %
-                 (create, index, read_only))
+                 "startServer(create=%d, index=%d, read_only=%d, "
+                 "transaction_timeout=%s)" %
+                 (create, index, read_only, transaction_timeout))
         path = "%s.%d" % (self.file, index)
         addr = self.addr[index]
         pid, server = forker.start_zeo_server(
-            'FileStorage', (path, create, read_only), addr, ro_svr)
+            'FileStorage', (path, create, read_only), addr, ro_svr,
+            transaction_timeout=transaction_timeout)
         self._pids.append(pid)
         self._servers.append(server)
 
@@ -61,15 +64,17 @@
 
     """Add Windows-specific scaffolding to the generic test suite."""
 
-    def startServer(self, create=1, index=0, read_only=0, ro_svr=0):
+    def startServer(self, create=1, index=0, read_only=0, ro_svr=0,
+                    transaction_timeout=None):
         zLOG.LOG("testZEO", zLOG.INFO,
-                 "startServer(create=%d, index=%d, read_only=%d)" %
-                 (create, index, read_only))
+                 "startServer(create=%d, index=%d, read_only=%d, "
+                 "transaction_timeout=%s)" %
+                 (create, index, read_only, transaction_timeout))
         path = "%s.%d" % (self.file, index)
         addr = self.addr[index]
         args = (path, '='+str(create), '='+str(read_only))
         _addr, test_addr, test_pid = forker.start_zeo_server(
-            'FileStorage', args, addr, ro_svr)
+            'FileStorage', args, addr, ro_svr, transaction_timeout)
         self._pids.append(test_pid)
         self._servers.append(test_addr)