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