Commit dfb0ad2d authored by Jim Fulton's avatar Jim Fulton Committed by GitHub

Merge pull request #42 from zopefoundation/test-cleanuo-2016-7-8

Test cleanup 2016 7 8
parents d825f158 73524dfe
......@@ -84,7 +84,7 @@ class CommonSetupTearDown(StorageTestBase):
self.file = 'storage_conf'
self._servers = []
self.caches = []
self.addr = [('localhost', 0)]
self.addr = [('127.0.0.1', 0)]
self.startServer()
def tearDown(self):
......@@ -127,7 +127,7 @@ class CommonSetupTearDown(StorageTestBase):
self.addr.append(self._getAddr())
def _getAddr(self):
return 'localhost', forker.get_port(self)
return '127.0.0.1', forker.get_port(self)
def getConfig(self, path, create, read_only):
raise NotImplementedError
......@@ -966,7 +966,7 @@ class TimeoutTests(CommonSetupTearDown):
self.assertRaises(ClientDisconnected, storage.tpc_finish, txn)
# Make sure it's logged as CRITICAL
for line in open("server-0.log"):
for line in open("server.log"):
if (('Transaction timeout after' in line) and
('CRITICAL ZEO.StorageServer' in line)
):
......
......@@ -18,7 +18,7 @@ The simplest client configuration specified a server address:
>>> storage.getName(), storage.__class__.__name__
... # doctest: +ELLIPSIS
("[('localhost', ...)] (connected)", 'ClientStorage')
("[('127.0.0.1', ...)] (connected)", 'ClientStorage')
>>> storage.blob_dir
>>> storage._storage
......
......@@ -39,7 +39,7 @@ class ZEOConfig:
if isinstance(addr, str):
self.logpath = addr+'.log'
else:
self.logpath = 'server-%s.log' % addr[1]
self.logpath = 'server.log'
addr = '%s:%s' % addr
self.address = addr
self.read_only = None
......@@ -198,10 +198,10 @@ def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
if zeo_conf is None or isinstance(zeo_conf, dict):
if port is None:
raise AssertionError("The port wasn't specified")
port = 0
if isinstance(port, int):
addr = 'localhost', port
addr = '127.0.0.1', port
else:
addr = port
......@@ -259,7 +259,7 @@ else:
def shutdown_zeo_server(stop):
stop()
def get_port(test=None):
def get_port(ignored=None):
"""Return a port that is not in use.
Checks if a port is in use by trying to connect to it. Assumes it
......@@ -270,23 +270,20 @@ def get_port(test=None):
Raises RuntimeError after 10 tries.
"""
if test is not None:
return get_port2(test)
for i in range(10):
port = random.randrange(20000, 30000)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
try:
s.connect(('localhost', port))
s.connect(('127.0.0.1', port))
except socket.error:
pass # Perhaps we should check value of error too.
else:
continue
try:
s1.connect(('localhost', port+1))
s1.connect(('127.0.0.1', port+1))
except socket.error:
pass # Perhaps we should check value of error too.
else:
......@@ -299,35 +296,11 @@ def get_port(test=None):
s1.close()
raise RuntimeError("Can't find port")
def get_port2(test):
for i in range(10):
while 1:
port = random.randrange(20000, 30000)
if port%3 == 0:
break
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind(('localhost', port+2))
except socket.error as e:
if e.args[0] != errno.EADDRINUSE:
raise
s.close()
continue
if not (can_connect(port) or can_connect(port+1)):
zope.testing.setupstack.register(test, s.close)
return port
s.close()
raise RuntimeError("Can't find port")
def can_connect(port):
c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
try:
c.connect(('localhost', port))
c.connect(('127.0.0.1', port))
except socket.error:
return False # Perhaps we should check value of error too.
else:
......@@ -349,7 +322,7 @@ def setUp(test):
"""
if port is None:
if addr is None:
port = get_port2(test)
port = 0
else:
port = addr[1]
elif addr is not None:
......@@ -370,11 +343,6 @@ def setUp(test):
test.globs['start_server'] = start_server
def get_port():
return get_port2(test)
test.globs['get_port'] = get_port
def stop_server(stop):
stop()
servers.remove(stop)
......
......@@ -17,7 +17,6 @@ import multiprocessing
import re
from ZEO.ClientStorage import ClientStorage, m64
from ZEO.tests.forker import get_port
from ZEO.tests import forker, Cache, CommitLockTests, ThreadTests
from ZEO.tests import IterationTests
from ZEO._compat import PY3
......@@ -275,10 +274,9 @@ class FileStorageRecoveryTests(StorageTestBase.StorageTestBase,
""" % tempfile.mktemp(dir='.')
def _new_storage(self):
port = get_port(self)
zconf = forker.ZEOConfig(('', port))
zconf = forker.ZEOConfig(('127.0.0.1', 0))
zport, stop = forker.start_zeo_server(self.getConfig(),
zconf, port)
zconf)
self._servers.append(stop)
blob_cache_dir = tempfile.mkdtemp(dir='.')
......@@ -775,7 +773,7 @@ def multiple_storages_invalidation_queue_is_not_insane():
>>> from transaction import commit
>>> fs1 = FileStorage('t1.fs')
>>> fs2 = FileStorage('t2.fs')
>>> server = StorageServer(('', get_port()), dict(fs1=fs1, fs2=fs2))
>>> server = StorageServer(None, storages=dict(fs1=fs1, fs2=fs2))
>>> s1 = StorageServerWrapper(server, 'fs1')
>>> s2 = StorageServerWrapper(server, 'fs2')
......@@ -804,7 +802,7 @@ def multiple_storages_invalidation_queue_is_not_insane():
>>> sorted([int(u64(oid)) for oid in oids])
[10, 11, 12, 13, 14]
>>> server.close()
>>> fs1.close(); fs2.close()
"""
def getInvalidationsAfterServerRestart():
......@@ -834,7 +832,7 @@ Let's create a file storage and stuff some data into it:
Now we'll open a storage server on the data, simulating a restart:
>>> fs = FileStorage('t.fs')
>>> sv = StorageServer(('', get_port()), dict(fs=fs))
>>> sv = StorageServer(None, dict(fs=fs))
>>> s = ZEOStorage(sv, sv.read_only)
>>> s.notify_connected(FauxConn())
>>> s.register('fs', False)
......@@ -868,7 +866,6 @@ need to be invalidated. This means we'll invalidate objects that
dont' need to be invalidated, however, that's better than verifying
caches.)
>>> sv.close()
>>> fs.close()
If a storage doesn't implement lastInvalidations, a client can still
......@@ -880,7 +877,7 @@ without this method:
... lastInvalidations = property()
>>> fs = FS('t.fs')
>>> sv = StorageServer(('', get_port()), dict(fs=fs))
>>> sv = StorageServer(None, dict(fs=fs))
>>> st = StorageServerWrapper(sv, 'fs')
>>> s = st.server
......@@ -1025,7 +1022,7 @@ def dont_log_poskeyerrors_on_server():
>>> cs.close()
>>> stop_server(admin)
>>> with open('server-%s.log' % addr[1]) as f:
>>> with open('server.log') as f:
... 'POSKeyError' in f.read()
False
"""
......@@ -1074,7 +1071,7 @@ def runzeo_without_configfile():
>>> import subprocess, re
>>> print(re.sub(b'\d\d+|[:]', b'', subprocess.Popen(
... [sys.executable, 'runzeo', '-a:%s' % get_port(), '-ft', '--test'],
... [sys.executable, 'runzeo', '-a:0', '-ft', '--test'],
... stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
... ).stdout.read()).decode('ascii'))
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
......@@ -1199,7 +1196,7 @@ constructor.
>>> db.close()
>>> @wait_until
... def check_for_test_label_1():
... with open('server-%s.log' % addr[1]) as f:
... with open('server.log') as f:
... for line in f:
... if 'test-label-1' in line:
... print(line.split()[1:4])
......@@ -1220,8 +1217,7 @@ You can specify the client label via a configuration file as well:
>>> db.close()
>>> @wait_until
... def check_for_test_label_2():
... with open('server-%s.log' % addr[1]) as f:
... for line in open('server-%s.log' % addr[1]):
... for line in open('server.log'):
... if 'test-label-2' in line:
... print(line.split()[1:4])
... return True
......@@ -1323,6 +1319,7 @@ def read(filename):
def runzeo_logrotate_on_sigusr2():
"""
>>> from ZEO.tests.forker import get_port
>>> port = get_port()
>>> with open('c', 'w') as r:
... _ = r.write('''
......@@ -1520,7 +1517,6 @@ class ServerManagingClientStorage(ClientStorage):
else:
server_blob_dir = 'server-'+blob_dir
self.globs = {}
port = forker.get_port2(self)
addr, stop = forker.start_zeo_server(
"""
<blobstorage>
......@@ -1531,7 +1527,6 @@ class ServerManagingClientStorage(ClientStorage):
</filestorage>
</blobstorage>
""" % (server_blob_dir, name+'.fs', extrafsoptions),
port=port,
)
zope.testing.setupstack.register(self, stop)
if shared:
......
......@@ -302,7 +302,7 @@ def ssl_client(**ssl_settings):
"""%import ZEO
<clientstorage>
server localhost:0
server 127.0.0.1:0
{}
</clientstorage>
""".format(ssl_conf(**ssl_settings))
......@@ -313,7 +313,7 @@ def create_server(**ssl_settings):
f.write(
"""
<zeo>
address localhost:0
address 127.0.0.1:0
{}
</zeo>
<mappingstorage>
......
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