[Zodb-checkins] CVS: Zope3/src/zodb/zeo/tests - connection.py:1.5.2.2

Jeremy Hylton jeremy@zope.com
Thu, 13 Feb 2003 12:40:15 -0500


Update of /cvs-repository/Zope3/src/zodb/zeo/tests
In directory cvs.zope.org:/tmp/cvs-serv4449/tests

Modified Files:
      Tag: ZODB3-2-integration-branch
	connection.py 
Log Message:
Cleanup error handling on disconnection.
Add sync() calls as needed.


=== Zope3/src/zodb/zeo/tests/connection.py 1.5.2.1 => 1.5.2.2 ===
--- Zope3/src/zodb/zeo/tests/connection.py:1.5.2.1	Mon Feb 10 17:08:29 2003
+++ Zope3/src/zodb/zeo/tests/connection.py	Thu Feb 13 12:40:14 2003
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -193,8 +193,9 @@
             try:
                 self._dostore()
                 break
-            except Disconnected:
+            except ClientDisconnected:
                 time.sleep(0.5)
+                self._storage.sync()
 
     def checkReadOnlyClient(self):
         # Open a read-only client to a read-write server; stores fail
@@ -256,7 +257,7 @@
         # Poll until the client disconnects
         self.pollDown()
         # Stores should fail now
-        self.assertRaises(Disconnected, self._dostore)
+        self.assertRaises(ClientDisconnected, self._dostore)
 
         # Restart the server
         self.startServer(create=False)
@@ -271,7 +272,8 @@
         # object is not in the cache.
         self.shutdownServer()
         self._storage = self.openClientStorage('test', 1000, wait=False)
-        self.assertRaises(Disconnected, self._storage.load, 'fredwash', '')
+        self.assertRaises(ClientDisconnected,
+                          self._storage.load, 'fredwash', '')
 
     def checkBasicPersistence(self):
         # Verify cached data persists across client storage instances.
@@ -335,18 +337,14 @@
             try:
                 self._dostore(oid, data=obj)
                 break
-            except (Disconnected, select.error,
-                    threading.ThreadError, socket.error):
+            except ClientDisconnected:
                 self.logger.warn("checkReconnection: "
                                  "Error after server restart; retrying.",
                                  exc_info=True)
                 get_transaction().abort()
-                time.sleep(0.1) # XXX how long to sleep
-            # XXX This is a bloody pain.  We're placing a heavy burden
-            # on users to catch a plethora of exceptions in order to
-            # write robust code.  Need to think about implementing
-            # John Heintz's suggestion to make sure all exceptions
-            # inherit from POSException.
+                self._storage.sync()
+        else:
+            self.fail("Could not reconnect to server")
         self.logger.warn("checkReconnection: finished")
 
     def checkBadMessage1(self):
@@ -377,7 +375,7 @@
 
         try:
             self._dostore()
-        except Disconnected:
+        except ClientDisconnected:
             pass
         else:
             self._storage.close()
@@ -493,7 +491,7 @@
         # Poll until the client disconnects
         self.pollDown()
         # Stores should fail now
-        self.assertRaises(Disconnected, self._dostore)
+        self.assertRaises(ClientDisconnected, self._dostore)
 
         # Restart the server
         self.startServer(create=False, read_only=True)
@@ -522,7 +520,7 @@
         # Poll until the client disconnects
         self.pollDown()
         # Stores should fail now
-        self.assertRaises(Disconnected, self._dostore)
+        self.assertRaises(ClientDisconnected, self._dostore)
 
         # Restart the server, this time read-write
         self.startServer(create=False)
@@ -554,9 +552,9 @@
             try:
                 self._dostore()
                 break
-            except (Disconnected, ReadOnlyError,
-                    select.error, threading.ThreadError, socket.error):
+            except (ClientDisconnected, ReadOnlyError):
                 time.sleep(0.1)
+                self._storage.sync()
         else:
             self.fail("Couldn't store after starting a read-write server")