[Zodb-checkins] CVS: Packages/ZEO - forker.py:1.1.2.1 testZEO.py:1.1.2.7
jeremy@digicool.com
jeremy@digicool.com
Fri, 27 Apr 2001 17:03:37 -0400 (EDT)
Update of /cvs-repository/Packages/ZEO/tests
In directory korak:/tmp/cvs-serv20840
Modified Files:
Tag: ZEO-ZRPC-Dev
testZEO.py
Added Files:
Tag: ZEO-ZRPC-Dev
forker.py
Log Message:
Update test to use all tests defined in ZODB.tests against FileStorage
Remove TestStorage subclasses in favor of forker module.
Updated _dostore() to handle the already_pickled arg.
Add new tests to GenericTests.
--- Added File forker.py in package Packages/ZEO ---
"""Library for forking storage server and connecting client storage"""
import asyncore
import os
import sys
import ThreadedAsync
import ZEO.ClientStorage, ZEO.StorageServer
class ZEOServerExit(asyncore.file_dispatcher):
"""Used to exit ZEO.StorageServer when run is done"""
def writable(self):
return 0
def readable(self):
return 1
def handle_read(self):
buf = self.recv(4)
if buf:
assert buf == "done"
asyncore.socket_map.clear()
def handle_close(self):
asyncore.socket_map.clear()
class ZEOClientExit:
"""Used by client to cause server to exit"""
def __init__(self, pipe):
self.pipe = pipe
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
rd, wr = os.pipe()
pid = os.fork()
if pid == 0:
# in the child, run the storage server
try:
os.close(wr)
ZEOServerExit(rd)
serv = ZEO.StorageServer.StorageServer(addr, {'1':storage})
asyncore.loop()
storage.close()
if domain == "AF_UNIX":
os.unlink(addr)
if cleanup:
cleanup()
finally:
os._exit(0)
else:
os.close(rd)
s = ZEO.ClientStorage.ClientStorage(addr, debug=1, client=cache)
return s, ZEOClientExit(wr), pid
--- Updated File testZEO.py in package Packages/ZEO --
--- testZEO.py 2001/04/25 21:05:42 1.1.2.6
+++ testZEO.py 2001/04/27 21:03:36 1.1.2.7
@@ -8,27 +8,15 @@
import unittest
import ZEO.ClientStorage, ZEO.StorageServer
-from ZEO.zrpc2 import ManagedServerConnection
import ThreadedAsync, ZEO.trigger
from ZEO import zeolog
+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 ZODB.tests import StorageTestBase, BasicStorage, VersionStorage
-
-class TestStorageServer(ZEO.StorageServer.StorageServer):
- def newConnection(self, sock, addr, nil):
- c = ManagedServerConnection(sock, addr, None, self)
- c.register_object(TestStorageProxy(self, c))
- zeolog.LOG("TSS", zeolog.INFO, "connected: %s" % c)
-
-class TestStorageProxy(ZEO.StorageServer.StorageProxy):
- def shutdown(self):
- self._StorageProxy__storage.close()
- os._exit(0)
+# Sorry Jim...
+from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \
+ TransactionalUndoStorage, TransactionalUndoVersionStorage, \
+ PackableStorage
ZERO = '\0'*8
import pickle
@@ -41,7 +29,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:
@@ -57,8 +46,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 = ''
@@ -84,15 +73,15 @@
raise RuntimeError, "unexpected ZEO response: no oid"
else:
for oid, serial in r:
- if type(serial) != types.StringType:
- raise serial
- else:
- d[oid] = serial
+ d[oid] = serial
return d
class GenericTests(ZEOTestBase,
BasicStorage.BasicStorage,
- VersionStorage.VersionStorage
+ VersionStorage.VersionStorage,
+ TransactionalUndoStorage.TransactionalUndoStorage,
+ PackableStorage.PackableStorage,
+ TransactionalUndoVersionStorage.TransactionalUndoVersionStorage,
):
"""An abstract base class for ZEO tests
@@ -112,9 +101,10 @@
getStorage() method.
"""
self.running = 1
- self.__sock = tempfile.mktemp()
- self.startServer()
- self._storage = ZEO.ClientStorage.ClientStorage(self.__sock)
+ client, exit, pid = forker.start_zeo(self.getStorage())
+ self._pid = pid
+ self._server = exit
+ self._storage = client
while not self._storage.is_connected():
time.sleep(0.1)
self.__super_setUp()
@@ -122,26 +112,9 @@
def tearDown(self):
"""Try to cause the tests to halt"""
self.running = 0
- self._storage._server.rpc.callAsync('shutdown')
- self._storage._rpc_mgr.close()
- os.waitpid(self.__pid, 0)
- os.unlink(self.__sock)
- self.delStorage()
+ self._server.close()
+ os.waitpid(self._pid, 0)
self.__super_tearDown()
-
- def startServer(self):
- self.__pid = os.fork()
- if self.__pid == 0:
- self.__storage = self.getStorage()
- d = {'1': self.__storage}
- self.__server = TestStorageServer(self.__sock, d)
- asyncore.loop()
- else:
- zeolog.LOG("test", zeolog.INFO, "forked %s" % self.__pid)
-
- def checkFirst(self):
- self._storage.tpc_begin(self._transaction)
- self._storage.tpc_abort(self._transaction)
class ZEOFileStorageTests(GenericTests):
__super_setUp = GenericTests.setUp