[Zodb-checkins] CVS: StandaloneZODB/ZEO/tests - forker.py:1.8 testZEO.py:1.14
Jeremy Hylton
jeremy@zope.com
Fri, 7 Sep 2001 16:46:38 -0400
Update of /cvs-repository/StandaloneZODB/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv796
Modified Files:
forker.py testZEO.py
Log Message:
Merge in zeo-1_0-branch
=== StandaloneZODB/ZEO/tests/forker.py 1.7 => 1.8 ===
import profile
import random
+import socket
import sys
import types
import ZEO.ClientStorage, ZEO.StorageServer
PROFILE = 0
+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:
+ s.connect(('localhost', port))
+ except socket.error:
+ # XXX check value of error?
+ return port
+ raise RuntimeError, "Can't find port"
+
if os.name == "nt":
def start_zeo_server(storage_name, args, port=None):
@@ -18,8 +37,7 @@
Returns the ZEO port, the test server port, and the pid.
"""
import ZEO.tests.winserver
- if port is None:
- port = random.randrange(20000, 30000)
+ port = get_port()
script = ZEO.tests.winserver.__file__
if script.endswith('.pyc'):
script = script[:-1]
@@ -93,8 +111,7 @@
"""
if domain == "AF_INET":
- import random
- addr = '', random.randrange(2000, 3000)
+ addr = '', get_port()
elif domain == "AF_UNIX":
import tempfile
addr = tempfile.mktemp()
=== StandaloneZODB/ZEO/tests/testZEO.py 1.13 => 1.14 ===
"""
- __super_setUp = StorageTestBase.StorageTestBase.setUp
+ __super_tearDown = StorageTestBase.StorageTestBase.tearDown
ports = []
for i in range(200):
@@ -242,7 +242,7 @@
self.shutdownServer()
# file storage appears to create four files
for ext in '', '.index', '.lock', '.tmp':
- path = self.__fs_base + ext
+ path = self.file + ext
if os.path.exists(path):
os.unlink(path)
for i in 0, 1:
@@ -325,13 +325,13 @@
getStorage() method.
"""
self.running = 1
- self.__fs_base = tempfile.mktemp()
+ self.file = tempfile.mktemp()
self.addr = '', self.ports.pop()
self._startServer()
self.__super_setUp()
def _startServer(self, create=1):
- fs = FileStorage(self.__fs_base, create=create)
+ fs = FileStorage(self.file, create=create)
self._pid, self._server = forker.start_zeo_server(fs, self.addr)
def openClientStorage(self, cache='', cache_size=200000, wait=1):