[Zodb-checkins] CVS: ZODB4/ZEO/tests - testZEO.py:1.31
Barry Warsaw
barry@wooz.org
Mon, 16 Dec 2002 16:16:38 -0500
Update of /cvs-repository/ZODB4/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv8453
Modified Files:
testZEO.py
Log Message:
Forward port from zodb3, use one true way to spawn the zeo server
subproc for both windows and unix.
=== ZODB4/ZEO/tests/testZEO.py 1.30 => 1.31 ===
--- ZODB4/ZEO/tests/testZEO.py:1.30 Wed Dec 4 16:58:15 2002
+++ ZODB4/ZEO/tests/testZEO.py Mon Dec 16 16:16:38 2002
@@ -30,22 +30,6 @@
from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle
-# Handle potential absence of removefs
-try:
- from ZODB.tests.StorageTestBase import removefs
-except ImportError:
- # for compatibility with Zope 2.5 &c.
- import errno
-
- def removefs(base):
- """Remove all files created by FileStorage with path base."""
- for ext in '', '.old', '.tmp', '.lock', '.index', '.pack':
- path = base + ext
- try:
- os.remove(path)
- except os.error, err:
- if err[0] != errno.ENOENT:
- raise
# ZODB test mixin classes
from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \
@@ -67,8 +51,8 @@
def invalidate(self, *args):
pass
-class MiscZEOTests:
+class MiscZEOTests:
"""ZEO tests that don't fit in elsewhere."""
def checkLargeUpdate(self):
@@ -97,10 +81,10 @@
finally:
storage2.close()
+
class GenericTests(
# Base class for all ZODB tests
StorageTestBase.StorageTestBase,
-
# ZODB test mixin classes (in the same order as imported)
BasicStorage.BasicStorage,
VersionStorage.VersionStorage,
@@ -113,13 +97,13 @@
RevisionStorage.RevisionStorage,
MTStorage.MTStorage,
ReadOnlyStorage.ReadOnlyStorage,
-
# ZEO test mixin classes (in the same order as imported)
Cache.StorageWithCache,
Cache.TransUndoStorageWithCache,
CommitLockTests.CommitLockTests,
ThreadTests.ThreadTests,
- MiscZEOTests # Locally defined (see above)
+ # Locally defined (see above)
+ MiscZEOTests
):
"""Combine tests from various origins in one class."""
@@ -137,73 +121,64 @@
# is no way for the test suite (a client) to inquire about it.
pass
-class UnixTests(GenericTests):
- """Add Unix-specific scaffolding to the generic test suite."""
+class FileStorageTests(GenericTests):
+ """Test ZEO backed by a FileStorage."""
def setUp(self):
zLOG.LOG("testZEO", zLOG.INFO, "setUp() %s" % self.id())
- client, exit, pid = forker.start_zeo(*self.getStorage())
+ zeoport, adminaddr, pid = forker.start_zeo_server(self.getConfig())
self._pids = [pid]
- self._servers = [exit]
- self._storage = client
- client.registerDB(DummyDB())
+ self._servers = [adminaddr]
+ self._storage = ClientStorage(zeoport, '1', cache_size=20000000,
+ min_disconnect_poll=0.5, wait=1)
+ self._storage.registerDB(DummyDB())
def tearDown(self):
self._storage.close()
for server in self._servers:
- server.close()
- for pid in self._pids:
- os.waitpid(pid, 0)
- self.delStorage()
-
- def getStorage(self):
- self.__fs_base = tempfile.mktemp()
- return 'FileStorage', (self.__fs_base, '1')
+ forker.shutdown_zeo_server(server)
+ if hasattr(os, 'waitpid'):
+ # Not in Windows Python until 2.3
+ for pid in self._pids:
+ os.waitpid(pid, 0)
+
+ def getConfig(self):
+ filename = self.__fs_base = tempfile.mktemp()
+ # Return a 1-tuple
+ return """\
+ <Storage>
+ type FileStorage
+ file_name %s
+ create yes
+ </Storage>
+ """ % filename
- def delStorage(self):
- removefs(self.__fs_base)
-class WindowsTests(GenericTests):
+class BDBTests(FileStorageTests):
+ """ZEO backed by a Berkeley Full storage."""
- """Add Windows-specific scaffolding to the generic test suite."""
+ def getStorage(self):
+ self._envdir = tempfile.mktemp()
+ # Return a 1-tuple
+ return """\
+ <Storage>
+ type BDBFullStorage
+ name %s
+ </Storage>
+ """ % self._envdir
- def setUp(self):
- zLOG.LOG("testZEO", zLOG.INFO, "setUp() %s" % self.id())
- args = self.getStorageInfo()
- name = args[0]
- args = args[1]
- zeo_addr, self.test_addr, self.test_pid = \
- forker.start_zeo_server(name, args)
- storage = ClientStorage(zeo_addr, wait=1, min_disconnect_poll=0.1)
- self._storage = storage
- storage.registerDB(DummyDB())
- def tearDown(self):
- self._storage.close()
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect(self.test_addr)
- s.close()
- # the connection should cause the storage server to die
- time.sleep(0.5)
- self.delStorage()
-
- def getStorageInfo(self):
- self.__fs_base = tempfile.mktemp()
- return 'FileStorage', (self.__fs_base, '1') # create=1
-
- def delStorage(self):
- removefs(self.__fs_base)
-
-if os.name == "posix":
- test_classes = [UnixTests]
-elif os.name == "nt":
- test_classes = [WindowsTests]
+test_classes = [FileStorageTests]
+try:
+ from BDBStorage.BDBFullStorage import BDBFullStorage
+except ImportError:
+ pass
else:
- raise RuntimeError, "unsupported os: %s" % os.name
+ test_classes.append(BDBTests)
-def test_suite():
+def test_suite():
# shutup warnings about mktemp
import warnings
warnings.filterwarnings("ignore", "mktemp")
@@ -213,6 +188,7 @@
sub = unittest.makeSuite(klass, 'check')
suite.addTest(sub)
return suite
+
if __name__ == "__main__":
unittest.main(defaultTest='test_suite')