[Zodb-checkins] CVS: StandaloneZODB/ZEO/tests - forker.py:1.10.4.4.2.2 stress.py:1.2.4.2.2.2 testZEO.py:1.16.4.4.2.2

Jeremy Hylton jeremy@zope.com
Fri, 26 Apr 2002 15:25:30 -0400


Update of /cvs-repository/StandaloneZODB/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv11377/tests

Modified Files:
      Tag: ZEO2-branch
	forker.py stress.py testZEO.py 
Log Message:
First step words protocol negotiation.

New client sends a 4-byte protocol id to the server.   XXX Is this
sufficient for now?

Also, rename "wait_for_server_on_startup" to "wait".  This change
affects a ctor calls in a bunch of files.


=== StandaloneZODB/ZEO/tests/forker.py 1.10.4.4.2.1 => 1.10.4.4.2.2 ===
                                             cache_size=cache_size,
                                             min_disconnect_poll=0.5,
-                                            wait_for_server_on_startup=1)
+                                            wait=1)
         return s, exit, pid


=== StandaloneZODB/ZEO/tests/stress.py 1.2.4.2.2.1 => 1.2.4.2.2.2 ===
 
 def _start_child(zaddr):
-    storage = ClientStorage(zaddr, debug=1, min_disconnect_poll=0.5,
-                            wait_for_server_on_startup=1)
+    storage = ClientStorage(zaddr, debug=1, min_disconnect_poll=0.5, wait=1)
     db = ZODB.DB(storage, pool_size=NUM_CONNECTIONS)
     setup(db.open())
     conns = []


=== StandaloneZODB/ZEO/tests/testZEO.py 1.16.4.4.2.1 => 1.16.4.4.2.2 ===
 import ThreadedAsync, ZEO.trigger
 from ZODB.FileStorage import FileStorage
+from ZODB.Transaction import Transaction
 import thread
 import zLOG
 
@@ -102,6 +103,63 @@
         obj = MinPO("X" * (10 * 128 * 1024))
         self._dostore(data=obj)
 
+    def checkCommitLockOnCommit(self):
+        self._checkCommitLock("tpc_finish")
+
+    def checkCommitLockOnAbort(self):
+        self._checkCommitLock("tpc_abort")
+
+    def _checkCommitLock(self, method_name):
+        # check the commit lock when a client attemps a transaction,
+        # but fails/exits before finishing the commit.
+
+        # Start on transaction normally.
+        t = Transaction()
+        self._storage.tpc_begin(t)
+
+        # Start a second transaction on a different connection without
+        # blocking the test thread.
+        self._storages = []
+        for i in range(3):
+            storage2 = self._duplicate_client()
+            t2 = Transaction()
+            tid = ZEO.ClientStorage.get_timestamp()
+            storage2._server.tpc_begin(tid, t2.user, t2.description,
+                                       t2._extension, None, ' ')
+            if i == 0:
+                storage2.close()
+            else:
+                self._storages.append((storage2, t2))
+
+        oid = self._storage.new_oid()
+        self._storage.store(oid, None, '', '', t)
+        self._storage.tpc_vote(t)
+        self._storage.status()
+        self._storage.tpc_finish(t)
+
+        for store, trans in self._storages:
+            store.tpc_abort(trans)
+            store.close()
+
+        # Make sure the server is still responsive
+        self._dostore()
+
+    def _duplicate_client(self):
+        "Open another ClientStorage to the same server."
+        # XXX argh it's hard to find the actual address
+        # The rpc mgr addr attribute is a list.  Each element in the
+        # list is a socket domain (AF_INET, AF_UNIX, etc.) and an
+        # address.
+        addr = self._storage._rpc_mgr.addr[0][1]
+        new = ZEO.ClientStorage.ClientStorage(addr, wait=1)
+        new.registerDB(DummyDB(), None)
+        return new
+
+    def _get_timestamp(self):
+        t = time.time()
+        t = apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
+        return `t`
+
 class ZEOFileStorageTests(GenericTests):
     __super_setUp = GenericTests.setUp
 
@@ -117,7 +175,7 @@
         addr = self._storage._rpc_mgr.addr[0][1]
         self._storage.close()
         self._storage = ZEO.ClientStorage.ClientStorage(addr, read_only=1,
-                                             wait_for_server_on_startup=1)
+                                                        wait=1)
 
     def getStorage(self):
         self.__fs_base = tempfile.mktemp()
@@ -365,7 +423,7 @@
         base = ZEO.ClientStorage.ClientStorage(self.addr,
                                                client=cache,
                                                cache_size=cache_size,
-                                               wait_for_server_on_startup=wait,
+                                               wait=wait,
                                                min_disconnect_poll=0.1)
         storage = PackWaitWrapper(base)
         storage.registerDB(DummyDB(), None)
@@ -403,8 +461,7 @@
         base = ZEO.ClientStorage.ClientStorage(self.addr,
                                                client=cache,
                                                cache_size=cache_size,
-                                               debug=1,
-                                               wait_for_server_on_startup=wait)
+                                               debug=1, wait=1)
         storage = PackWaitWrapper(base)
         storage.registerDB(DummyDB(), None)
         return storage