[Zodb-checkins] CVS: ZODB4/ZEO/tests - ConnectionTests.py:1.2

Barry Warsaw barry@wooz.org
Mon, 16 Dec 2002 16:15:21 -0500


Update of /cvs-repository/ZODB4/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv8268

Modified Files:
	ConnectionTests.py 
Log Message:
Forward port from zodb3, use one true way to spawn the zeo server
subproc for both windows and unix.

Also use True/False for all booleans.

One addition made here that needs to be backported to zodb3: split the
tests between connection tests and reconnection tests, the latter
which set the `keep' flag to true for the initial database creation.

Tests move to the ReconnectionTests class:

    - checkReadOnlyStorage
    - checkReadOnlyFallbackReadOnlyServer
    - checkReconnectReadOnly
    - checkReconnectFallback
    - checkReconnectUpgrade
    - checkReconnectSwitch


=== ZODB4/ZEO/tests/ConnectionTests.py 1.1 => 1.2 === (429/529 lines abridged)
--- ZODB4/ZEO/tests/ConnectionTests.py:1.1	Fri Nov 22 16:24:53 2002
+++ ZODB4/ZEO/tests/ConnectionTests.py	Mon Dec 16 16:15:20 2002
@@ -11,21 +11,23 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-import asyncore
+
 import os
+import sys
+import time
 import random
 import select
 import socket
-import sys
+import asyncore
 import tempfile
 import threading
-import time
 
 import zLOG
 
 from ZEO.ClientStorage import ClientStorage
 from ZEO.Exceptions import Disconnected
 from ZEO.zrpc.marshal import Marshaller
+from ZEO.tests import forker
 
 from Transaction import get_transaction
 from ZODB.POSException import ReadOnlyError
@@ -35,22 +37,22 @@
 from ZODB.tests.StorageTestBase import zodb_pickle, zodb_unpickle
 from ZODB.tests.StorageTestBase import handle_all_serials, ZERO
 
+
 class DummyDB:
-    def invalidate(self, *args):
+    def invalidate(self, *args, **kws):
         pass
 
+
 class ConnectionTests(StorageTestBase):
     """Tests that explicitly manage the server process.
 
     To test the cache or re-connection, these test cases explicit
     start and stop a ZEO storage server.
-
-    This must be subclassed; the subclass must provide implementations
-    of startServer() and shutdownServer().
     """
 

[-=- -=- -=- 429 lines omitted -=- -=- -=-]

+        self.shutdownServer()
+        self._servers = []
+        self._pids = []
+        # Poll until the client disconnects
+        self.pollDown()
+        # Stores should fail now
+        self.assertRaises(Disconnected, self._dostore)
+
+        # Restart the server, this time read-write
+        self.startServer(create=0)
+        # Poll until the client sconnects
+        self.pollUp()
+        # Stores should now succeed
+        self._dostore()
+
+    def checkReconnectSwitch(self):
+        # A fallback client initially connects to a read-only server,
+        # then discovers a read-write server and switches to that
+
+        # We don't want the read-write server created by setUp()
+        self.shutdownServer()
+        self._servers = []
+        self._pids = []
+
+        # Allocate a second address (for the second server)
+        self._newAddr()
+
+        # Start a read-only server
+        self.startServer(create=0, index=0, read_only=1)
+        # Start a client in fallback mode
+        self._storage = self.openClientStorage(read_only_fallback=1)
+        # Stores should fail here
+        self.assertRaises(ReadOnlyError, self._dostore)
+
+        # Start a read-write server
+        self.startServer(index=1, read_only=0)
+        # After a while, stores should work
+        for i in range(300): # Try for 30 seconds
+            try:
+                self._dostore()
+                break
+            except (Disconnected, ReadOnlyError,
+                    select.error, threading.ThreadError, socket.error):
+                time.sleep(0.1)
+        else:
+            self.fail("Couldn't store after starting a read-write server")
+
 
 class MSTThread(threading.Thread):