Commit 6e882844 authored by Jeremy Hylton's avatar Jeremy Hylton

Updates so that it passes all tests

parent c5a56790
...@@ -32,23 +32,7 @@ class ZEOClientExit: ...@@ -32,23 +32,7 @@ class ZEOClientExit:
def close(self): def close(self):
os.write(self.pipe, "done") os.write(self.pipe, "done")
def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"): def start_zeo_server(storage, addr):
"""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
rd, wr = os.pipe() rd, wr = os.pipe()
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
...@@ -67,6 +51,26 @@ def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"): ...@@ -67,6 +51,26 @@ def start_zeo(storage, cache=None, cleanup=None, domain="AF_INET"):
os._exit(0) os._exit(0)
else: else:
os.close(rd) os.close(rd)
s = ZEO.ClientStorage.ClientStorage(addr, debug=1, client=cache) return pid, ZEOClientExit(wr)
return s, ZEOClientExit(wr), pid
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
"""Test suite for ZEO based on ZODB.tests""" """Test suite for ZEO based on ZODB.tests"""
import asyncore
import os import os
import random
import signal
import tempfile import tempfile
import time import time
import types import types
...@@ -10,23 +9,31 @@ import unittest ...@@ -10,23 +9,31 @@ import unittest
import ZEO.ClientStorage, ZEO.StorageServer import ZEO.ClientStorage, ZEO.StorageServer
import ThreadedAsync, ZEO.trigger import ThreadedAsync, ZEO.trigger
from ZEO.tests import forker
# XXX The ZODB.tests package contains a grab bad things, including, from ZEO.tests import forker
# apparently, a collection of modules that define mixin classes
# containing tests cases.
from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage # Sorry Jim...
from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \
TransactionalUndoStorage, TransactionalUndoVersionStorage, \
PackableStorage, Synchronization
ZERO = '\0'*8 ZERO = '\0'*8
import pickle import pickle
class FakeDB: class DummyDB:
"""A ClientStorage must be registered with a DB to function"""
def invalidate(self, *args): def invalidate(self, *args):
pass 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): class ZEOTestBase(StorageTestBase.StorageTestBase):
"""Version of the storage test class that supports ZEO. """Version of the storage test class that supports ZEO.
...@@ -35,7 +42,8 @@ class ZEOTestBase(StorageTestBase.StorageTestBase): ...@@ -35,7 +42,8 @@ class ZEOTestBase(StorageTestBase.StorageTestBase):
will get no later than the return value from vote. 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. """Do a complete storage transaction.
The defaults are: The defaults are:
...@@ -51,8 +59,8 @@ class ZEOTestBase(StorageTestBase.StorageTestBase): ...@@ -51,8 +59,8 @@ class ZEOTestBase(StorageTestBase.StorageTestBase):
if revid is None: if revid is None:
revid = ZERO revid = ZERO
if data is None: if data is None:
data = pickle.dumps(7) data = 7
else: if not already_pickled:
data = pickle.dumps(data) data = pickle.dumps(data)
if version is None: if version is None:
version = '' version = ''
...@@ -67,6 +75,7 @@ class ZEOTestBase(StorageTestBase.StorageTestBase): ...@@ -67,6 +75,7 @@ class ZEOTestBase(StorageTestBase.StorageTestBase):
s2 = self._get_serial(r2) s2 = self._get_serial(r2)
self._storage.tpc_finish(self._transaction) self._storage.tpc_finish(self._transaction)
# s1, s2 can be None or dict # s1, s2 can be None or dict
assert not (s1 and s2)
return s1 and s1[oid] or s2 and s2[oid] return s1 and s1[oid] or s2 and s2[oid]
def _get_serial(self, r): def _get_serial(self, r):
...@@ -78,15 +87,16 @@ class ZEOTestBase(StorageTestBase.StorageTestBase): ...@@ -78,15 +87,16 @@ class ZEOTestBase(StorageTestBase.StorageTestBase):
raise RuntimeError, "unexpected ZEO response: no oid" raise RuntimeError, "unexpected ZEO response: no oid"
else: else:
for oid, serial in r: for oid, serial in r:
if type(serial) != types.StringType: if isinstance(serial, Exception):
raise serial raise serial
else: d[oid] = serial
d[oid] = serial
return d return d
class GenericTests(ZEOTestBase, class GenericTests(ZEOTestBase,
BasicStorage.BasicStorage, BasicStorage.BasicStorage,
VersionStorage.VersionStorage, VersionStorage.VersionStorage,
PackableStorage.PackableStorage,
Synchronization.SynchronizedStorage,
): ):
"""An abstract base class for ZEO tests """An abstract base class for ZEO tests
...@@ -106,27 +116,20 @@ class GenericTests(ZEOTestBase, ...@@ -106,27 +116,20 @@ class GenericTests(ZEOTestBase,
getStorage() method. getStorage() method.
""" """
self.running = 1 self.running = 1
s = self.__storage = self.getStorage() client, exit, pid = forker.start_zeo(self.getStorage())
storage, exit, pid = forker.start_zeo(s)
self._pid = pid self._pid = pid
self._server_exit = exit self._server = exit
self._storage = storage self._storage = PackWaitWrapper(client)
self._storage.registerDB(FakeDB(), None) client.registerDB(DummyDB(), None)
self.__super_setUp() self.__super_setUp()
def tearDown(self): def tearDown(self):
"""Try to cause the tests to halt""" """Try to cause the tests to halt"""
self.running = 0 self.running = 0
# XXX This only works on Unix self._server.close()
self._server_exit.close()
os.waitpid(self._pid, 0) os.waitpid(self._pid, 0)
self.delStorage()
self.__super_tearDown() self.__super_tearDown()
def checkFirst(self):
self._storage.tpc_begin(self._transaction)
self._storage.tpc_abort(self._transaction)
class ZEOFileStorageTests(GenericTests): class ZEOFileStorageTests(GenericTests):
__super_setUp = GenericTests.setUp __super_setUp = GenericTests.setUp
...@@ -143,8 +146,7 @@ class ZEOFileStorageTests(GenericTests): ...@@ -143,8 +146,7 @@ class ZEOFileStorageTests(GenericTests):
# file storage appears to create three files # file storage appears to create three files
for ext in '', '.index', '.lock', '.tmp': for ext in '', '.index', '.lock', '.tmp':
path = self.__fs_base + ext path = self.__fs_base + ext
if os.path.exists(path): os.unlink(path)
os.unlink(path)
def main(): def main():
import sys, getopt import sys, getopt
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment