[Zodb-checkins] CVS: StandaloneZODB/ZEO/tests - testZEO.py:1.9.2.1

Jeremy Hylton jeremy@zope.com
Tue, 7 Aug 2001 18:32:31 -0400


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

Modified Files:
      Tag: zeo-1_0-branch
	testZEO.py 
Log Message:
Variety of fixes that get testZEO to run successfully again

Make ports for ZEO testing more random, reducing likelihood of port
already in use errors.

In tests for reconnection, catch ClientDisconnected, thread.error, and
socket.error.

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.

Add test_suite() method for conformance with Zope testing style.


=== StandaloneZODB/ZEO/tests/testZEO.py 1.9 => 1.9.2.1 ===
 import os
 import random
+import socket
 import sys
 import tempfile
 import time
@@ -175,8 +176,7 @@
     __super_setUp = StorageTestBase.StorageTestBase.setUp
     __super_tearDown = StorageTestBase.StorageTestBase.tearDown
 
-    ports = range(29000, 30000, 10) # enough for 100 tests
-    random.shuffle(ports)
+    ports = [random.randrange(25000, 30000) for i in range(200)]
 
     def setUp(self):
         """Start a ZEO server using a Unix domain socket
@@ -186,7 +186,8 @@
         """
         self.running = 1
         self.__fs_base = tempfile.mktemp()
-        self.addr = '', random.randrange(2000, 3000)
+        port = self.ports.pop()
+        self.addr = '', port
         pid, exit = self._startServer()
         self._pid = pid
         self._server = exit
@@ -275,10 +276,16 @@
         self._pid, self._server = self._startServer(create=0)
         oid = self._storage.new_oid()
         obj = MinPO(12)
+        # 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. 
+
         while 1:
             try:
                 revid1 = self._dostore(oid, data=obj)
-            except (ClientDisconnected, thread.error), err:
+            except (ClientDisconnected, thread.error, socket.error), err:
                 get_transaction().abort()
                 time.sleep(0.1)
             else:
@@ -304,6 +311,9 @@
             if meth.startswith(name):
                 suite.addTest(klass(meth))
     return suite
+
+def test_suite():
+    return makeTestSuite()
 
 def main():
     import sys, getopt