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

Jeremy Hylton jeremy@zope.com
Thu, 30 May 2002 23:17:55 -0400


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

Modified Files:
      Tag: ZEO2-branch
	testZEO.py 
Log Message:
Several small fixes to Windows test code.

Define WindowsConnectionTests subclass to handle different mechanism
for shutting down servers on Windows.  Make sure socket addresses say
'localhost' because '' won't work on Windows.


=== StandaloneZODB/ZEO/tests/testZEO.py 1.16.4.4.2.12 => 1.16.4.4.2.13 ===
 
     def _getAddr(self):
-        return '', self.ports.pop()
-
-    def _startServer(self, create=1, index=0):
-        path = "%s.%d" % (self.file, index)
-        addr = self.addr[index]
-        pid, server = forker.start_zeo_server('FileStorage',
-                                              (path, create), addr)
-        self._pids.append(pid)
-        self._servers.append(server)
-
-    def shutdownServer(self, index=0):
-        if self.running:
-            self.running = 0
-            self._servers[index].close()
-            try:
-                os.waitpid(self._pids[index], 0)
-            except os.error:
-                pass
+        return 'localhost', self.ports.pop()
 
     def openClientStorage(self, cache='', cache_size=200000, wait=1):
         base = ZEO.ClientStorage.ClientStorage(self.addr,
@@ -247,11 +230,17 @@
             for ext in '', '.index', '.lock', '.tmp':
                 path = "%s.%s%s" % (self.file, i, ext)
                 if os.path.exists(path):
-                    os.unlink(path)
+                    try:
+                        os.unlink(path)
+                    except os.error:
+                        pass
         for i in 0, 1:
             path = "c1-test-%d.zec" % i
             if os.path.exists(path):
-                os.unlink(path)
+                try:
+                    os.unlink(path)
+                except os.error:
+                    pass
         self.__super_tearDown()
 
     def checkMultipleAddresses(self):
@@ -298,6 +287,7 @@
 
         # To verify that the cache is being used, the test closes the
         # server and then starts a new client with the server down.
+        # When the server is down, a load() gets the data from its cache.
 
         self._storage = self.openClientStorage('test', 100000, wait=1)
         oid = self._storage.new_oid()
@@ -371,10 +361,29 @@
             # inherit from POSException.
         zLOG.LOG("checkReconnection", zLOG.INFO, "finished")
 
+class WindowsConnectionTests(ConnectionTests):
+    
+    def _startServer(self, create=1, index=0):
+        path = "%s.%d" % (self.file, index)
+        addr = self.addr[index]
+        _addr, test_addr, test_pid = forker.start_zeo_server('FileStorage',
+                                                 (path, str(create)), addr)
+        self._pids.append(test_pid)
+        self._servers.append(test_addr)
+
+    def shutdownServer(self, index=0):
+        if self.running:
+            self.running = 0
+            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            s.connect(self._servers[index])
+            s.close()
+            # XXX waitpid() isn't available until Python 2.3
+            time.sleep(0.5)
+
 if os.name == "posix":
     test_classes = ZEOFileStorageTests, ConnectionTests
 elif os.name == "nt":
-    test_classes = WindowsZEOFileStorageTests, ConnectionTests
+    test_classes = WindowsZEOFileStorageTests, WindowsConnectionTests
 else:
     raise RuntimeError, "unsupported os: %s" % os.name