Commit 16ef5d3e authored by Jeremy Hylton's avatar Jeremy Hylton

Revise the test framework to use ZConfig instead of a custom argv.

parent edaab632
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import os import os
import sys import sys
import time import time
import random
import socket import socket
import asyncore import asyncore
import tempfile import tempfile
...@@ -37,13 +38,8 @@ from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \ ...@@ -37,13 +38,8 @@ from ZODB.tests import StorageTestBase, BasicStorage, VersionStorage, \
PackableStorage, Synchronization, ConflictResolution, RevisionStorage, \ PackableStorage, Synchronization, ConflictResolution, RevisionStorage, \
MTStorage, ReadOnlyStorage MTStorage, ReadOnlyStorage
# ZEO imports
from ZEO.ClientStorage import ClientStorage from ZEO.ClientStorage import ClientStorage
# ZEO test support
from ZEO.tests import forker, Cache from ZEO.tests import forker, Cache
# ZEO test mixin classes
from ZEO.tests import CommitLockTests, ThreadTests from ZEO.tests import CommitLockTests, ThreadTests
class DummyDB: class DummyDB:
...@@ -80,6 +76,26 @@ class MiscZEOTests: ...@@ -80,6 +76,26 @@ class MiscZEOTests:
finally: finally:
storage2.close() storage2.close()
def get_port():
"""Return a port that is not in use.
Checks if a port is in use by trying to connect to it. Assumes it
is not in use if connect raises an exception.
Raises RuntimeError after 10 tries.
"""
for i in range(10):
port = random.randrange(20000, 30000)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
try:
s.connect(('localhost', port))
except socket.error:
# XXX check value of error?
return port
finally:
s.close()
raise RuntimeError, "Can't find port"
class GenericTests( class GenericTests(
# Base class for all ZODB tests # Base class for all ZODB tests
...@@ -109,15 +125,20 @@ class GenericTests( ...@@ -109,15 +125,20 @@ class GenericTests(
def setUp(self): def setUp(self):
zLOG.LOG("testZEO", zLOG.INFO, "setUp() %s" % self.id()) zLOG.LOG("testZEO", zLOG.INFO, "setUp() %s" % self.id())
zeoport, adminaddr, pid = forker.start_zeo_server(self.getConfig()) port = get_port()
zconf = forker.ZEOConfig(('', port))
zport, adminaddr, pid, path = forker.start_zeo_server(self.getConfig(),
zconf, port)
self._pids = [pid] self._pids = [pid]
self._servers = [adminaddr] self._servers = [adminaddr]
self._storage = ClientStorage(zeoport, '1', cache_size=20000000, self._conf_path = path
self._storage = ClientStorage(zport, '1', cache_size=20000000,
min_disconnect_poll=0.5, wait=1) min_disconnect_poll=0.5, wait=1)
self._storage.registerDB(DummyDB(), None) self._storage.registerDB(DummyDB(), None)
def tearDown(self): def tearDown(self):
self._storage.close() self._storage.close()
os.remove(self._conf_path)
for server in self._servers: for server in self._servers:
forker.shutdown_zeo_server(server) forker.shutdown_zeo_server(server)
if hasattr(os, 'waitpid'): if hasattr(os, 'waitpid'):
...@@ -150,7 +171,7 @@ class FileStorageTests(GenericTests): ...@@ -150,7 +171,7 @@ class FileStorageTests(GenericTests):
def getConfig(self): def getConfig(self):
filename = self.__fs_base = tempfile.mktemp() filename = self.__fs_base = tempfile.mktemp()
return """\ return """\
<filestorage> <filestorage 1>
path %s path %s
</filestorage> </filestorage>
""" % filename """ % filename
...@@ -162,7 +183,7 @@ class BDBTests(FileStorageTests): ...@@ -162,7 +183,7 @@ class BDBTests(FileStorageTests):
def getConfig(self): def getConfig(self):
self._envdir = tempfile.mktemp() self._envdir = tempfile.mktemp()
return """\ return """\
<fullstorage> <fullstorage 1>
name %s name %s
</fullstorage> </fullstorage>
""" % self._envdir """ % self._envdir
...@@ -171,7 +192,7 @@ class MappingStorageTests(FileStorageTests): ...@@ -171,7 +192,7 @@ class MappingStorageTests(FileStorageTests):
"""ZEO backed by a Mapping storage.""" """ZEO backed by a Mapping storage."""
def getConfig(self): def getConfig(self):
return """<mappingstorage/>""" return """<mappingstorage 1/>"""
# Tests which MappingStorage can't possibly pass, because it doesn't # Tests which MappingStorage can't possibly pass, because it doesn't
# support versions or undo. # support versions or undo.
......
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