[Zodb-checkins] CVS: Packages/ZEO - forker.py:1.2 testZEO.py:1.3
jeremy@digicool.com
jeremy@digicool.com
Tue, 1 May 2001 15:54:34 -0400 (EDT)
Update of /cvs-repository/Packages/ZEO/tests
In directory korak:/tmp/cvs-serv8380/tests
Modified Files:
forker.py testZEO.py
Log Message:
Updates so that it passes all tests
--- Updated File forker.py in package Packages/ZEO --
--- forker.py 2001/04/27 17:32:19 1.1
+++ forker.py 2001/05/01 19:54:33 1.2
@@ -32,23 +32,7 @@
def close(self):
os.write(self.pipe, "done")
-def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"):
- """Setup ZEO client-server for storage.
-
- Returns a ClientStorage instance and a ZEOClientExit instance.
-
- XXX Don't know if os.pipe() will work on Windows.
- """
-
- if domain == "AF_INET":
- import random
- addr = '', random.randrange(2000, 3000)
- elif domain == "AF_UNIX":
- import tempfile
- addr = tempfile.mktemp()
- else:
- raise ValueError, "bad domain: %s" % domain
-
+def start_zeo_server(storage, addr):
rd, wr = os.pipe()
pid = os.fork()
if pid == 0:
@@ -67,6 +51,26 @@
os._exit(0)
else:
os.close(rd)
- s = ZEO.ClientStorage.ClientStorage(addr, debug=1, client=cache)
- return s, ZEOClientExit(wr), pid
+ return pid, ZEOClientExit(wr)
+
+def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"):
+ """Setup ZEO client-server for storage.
+
+ Returns a ClientStorage instance and a ZEOClientExit instance.
+
+ XXX Don't know if os.pipe() will work on Windows.
+ """
+
+ if domain == "AF_INET":
+ import random
+ addr = '', random.randrange(2000, 3000)
+ elif domain == "AF_UNIX":
+ import tempfile
+ addr = tempfile.mktemp()
+ else:
+ raise ValueError, "bad domain: %s" % domain
+
+ pid, exit = start_zeo_server(storage, addr)
+ s = ZEO.ClientStorage.ClientStorage(addr, debug=1, client=cache)
+ return s, exit, pid
--- Updated File testZEO.py in package Packages/ZEO --
--- testZEO.py 2001/04/27 17:32:19 1.2
+++ testZEO.py 2001/05/01 19:54:33 1.3
@@ -1,8 +1,7 @@
"""Test suite for ZEO based on ZODB.tests"""
+import asyncore
import os
-import random
-import signal
import tempfile
import time
import types
@@ -10,23 +9,31 @@
import ZEO.ClientStorage, ZEO.StorageServer
import ThreadedAsync, ZEO.trigger
-from ZEO.tests import forker
-# XXX The ZODB.tests package contains a grab bad things, including,
-# apparently, a collection of modules that define mixin classes
-# containing tests cases.
+from ZEO.tests import forker
-from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage
+# Sorry Jim...
+from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \
+ TransactionalUndoStorage, TransactionalUndoVersionStorage, \
+ PackableStorage, Synchronization
ZERO = '\0'*8
import pickle
-
-class FakeDB:
- """A ClientStorage must be registered with a DB to function"""
+class DummyDB:
def invalidate(self, *args):
pass
+class PackWaitWrapper:
+ def __init__(self, storage):
+ self.storage = storage
+
+ def __getattr__(self, attr):
+ return getattr(self.storage, attr)
+
+ def pack(self, t, f):
+ self.storage.pack(t, f, wait=1)
+
class ZEOTestBase(StorageTestBase.StorageTestBase):
"""Version of the storage test class that supports ZEO.
@@ -35,7 +42,8 @@
will get no later than the return value from vote.
"""
- def _dostore(self, oid=None, revid=None, data=None, version=None):
+ def _dostore(self, oid=None, revid=None, data=None, version=None,
+ already_pickled=0):
"""Do a complete storage transaction.
The defaults are:
@@ -51,8 +59,8 @@
if revid is None:
revid = ZERO
if data is None:
- data = pickle.dumps(7)
- else:
+ data = 7
+ if not already_pickled:
data = pickle.dumps(data)
if version is None:
version = ''
@@ -67,6 +75,7 @@
s2 = self._get_serial(r2)
self._storage.tpc_finish(self._transaction)
# s1, s2 can be None or dict
+ assert not (s1 and s2)
return s1 and s1[oid] or s2 and s2[oid]
def _get_serial(self, r):
@@ -78,15 +87,16 @@
raise RuntimeError, "unexpected ZEO response: no oid"
else:
for oid, serial in r:
- if type(serial) != types.StringType:
+ if isinstance(serial, Exception):
raise serial
- else:
- d[oid] = serial
+ d[oid] = serial
return d
class GenericTests(ZEOTestBase,
BasicStorage.BasicStorage,
VersionStorage.VersionStorage,
+ PackableStorage.PackableStorage,
+ Synchronization.SynchronizedStorage,
):
"""An abstract base class for ZEO tests
@@ -106,27 +116,20 @@
getStorage() method.
"""
self.running = 1
- s = self.__storage = self.getStorage()
- storage, exit, pid = forker.start_zeo(s)
+ client, exit, pid = forker.start_zeo(self.getStorage())
self._pid = pid
- self._server_exit = exit
- self._storage = storage
- self._storage.registerDB(FakeDB(), None)
+ self._server = exit
+ self._storage = PackWaitWrapper(client)
+ client.registerDB(DummyDB(), None)
self.__super_setUp()
def tearDown(self):
"""Try to cause the tests to halt"""
self.running = 0
- # XXX This only works on Unix
- self._server_exit.close()
+ self._server.close()
os.waitpid(self._pid, 0)
- self.delStorage()
self.__super_tearDown()
- def checkFirst(self):
- self._storage.tpc_begin(self._transaction)
- self._storage.tpc_abort(self._transaction)
-
class ZEOFileStorageTests(GenericTests):
__super_setUp = GenericTests.setUp
@@ -143,8 +146,7 @@
# file storage appears to create three files
for ext in '', '.index', '.lock', '.tmp':
path = self.__fs_base + ext
- if os.path.exists(path):
- os.unlink(path)
+ os.unlink(path)
def main():
import sys, getopt