Commit cfa60a7a authored by Jeremy Hylton's avatar Jeremy Hylton

Merge in zeo-1_0-branch

parent 4dfb633e
......@@ -4,12 +4,31 @@ import asyncore
import os
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 @@ if os.name == "nt":
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 @@ else:
"""
if domain == "AF_INET":
import random
addr = '', random.randrange(2000, 3000)
addr = '', get_port()
elif domain == "AF_UNIX":
import tempfile
addr = tempfile.mktemp()
......
......@@ -222,7 +222,7 @@ class ConnectionTests(ZEOTestBase):
start and stop a ZEO storage server.
"""
__super_setUp = StorageTestBase.StorageTestBase.setUp
__super_tearDown = StorageTestBase.StorageTestBase.tearDown
ports = []
for i in range(200):
......@@ -242,7 +242,7 @@ class ConnectionTests(ZEOTestBase):
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 @@ class UnixConnectionTests(ConnectionTests):
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):
......
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