Commit 71b173c0 authored by Barry Warsaw's avatar Barry Warsaw

Back porting fixes from zodb4 to specify a `keep' flag on the

storage's artifacts.  Some tests expect to reconnect in read-only mode
to a previously created storage.
parent 2177ef77
This diff is collapsed.
...@@ -17,10 +17,8 @@ import os ...@@ -17,10 +17,8 @@ import os
import sys import sys
import time import time
import errno import errno
import types
import random import random
import socket import socket
import asyncore
import tempfile import tempfile
import traceback import traceback
...@@ -31,6 +29,7 @@ PROFILE = 0 ...@@ -31,6 +29,7 @@ PROFILE = 0
if PROFILE: if PROFILE:
import hotshot import hotshot
def get_port(): def get_port():
"""Return a port that is not in use. """Return a port that is not in use.
...@@ -53,7 +52,7 @@ def get_port(): ...@@ -53,7 +52,7 @@ def get_port():
raise RuntimeError, "Can't find port" raise RuntimeError, "Can't find port"
def start_zeo_server(conf, addr=None, ro_svr=0): def start_zeo_server(conf, addr=None, ro_svr=0, keep=0):
"""Start a ZEO server in a separate process. """Start a ZEO server in a separate process.
Returns the ZEO port, the test server port, and the pid. Returns the ZEO port, the test server port, and the pid.
...@@ -76,6 +75,8 @@ def start_zeo_server(conf, addr=None, ro_svr=0): ...@@ -76,6 +75,8 @@ def start_zeo_server(conf, addr=None, ro_svr=0):
args = [sys.executable, script, '-C', tmpfile] args = [sys.executable, script, '-C', tmpfile]
if ro_svr: if ro_svr:
args.append('-r') args.append('-r')
if keep:
args.append('-k')
args.append(str(port)) args.append(str(port))
d = os.environ.copy() d = os.environ.copy()
d['PYTHONPATH'] = os.pathsep.join(sys.path) d['PYTHONPATH'] = os.pathsep.join(sys.path)
......
...@@ -20,12 +20,10 @@ platform-dependent scaffolding. ...@@ -20,12 +20,10 @@ platform-dependent scaffolding.
# System imports # System imports
import unittest import unittest
# Import the actual test class # Import the actual test class
from ZEO.tests.ConnectionTests import ConnectionTests from ZEO.tests import ConnectionTests
class FileStorageConnectionTests(ConnectionTests): class FileStorageConfig:
"""Add FileStorage-specific test."""
def getConfig(self, path, create, read_only): def getConfig(self, path, create, read_only):
return """\ return """\
<Storage> <Storage>
...@@ -38,9 +36,7 @@ class FileStorageConnectionTests(ConnectionTests): ...@@ -38,9 +36,7 @@ class FileStorageConnectionTests(ConnectionTests):
read_only and 'yes' or 'no') read_only and 'yes' or 'no')
class BDBConnectionTests(FileStorageConnectionTests): class BerkeleyStorageConfig:
"""Berkeley storage tests."""
def getConfig(self, path, create, read_only): def getConfig(self, path, create, read_only):
# Full always creates and doesn't have a read_only flag # Full always creates and doesn't have a read_only flag
return """\ return """\
...@@ -51,13 +47,42 @@ class BDBConnectionTests(FileStorageConnectionTests): ...@@ -51,13 +47,42 @@ class BDBConnectionTests(FileStorageConnectionTests):
</Storage>""" % (path, read_only) </Storage>""" % (path, read_only)
test_classes = [FileStorageConnectionTests] class FileStorageConnectionTests(
FileStorageConfig,
ConnectionTests.ConnectionTests
):
"""FileStorage-specific connection tests."""
class FileStorageReconnectionTests(
FileStorageConfig,
ConnectionTests.ReconnectionTests
):
"""FileStorage-specific re-connection tests."""
class BDBConnectionTests(
BerkeleyStorageConfig,
ConnectionTests.ConnectionTests
):
"""Berkeley storage connection tests."""
class BDBReconnectionTests(
BerkeleyStorageConfig,
ConnectionTests.ReconnectionTests
):
"""Berkeley storage re-connection tests."""
test_classes = [FileStorageConnectionTests, FileStorageReconnectionTests]
try: try:
from bsddb3Storage.Full import Full from bsddb3Storage.Full import Full
except ImportError: except ImportError:
pass pass
else: else:
test_classes.append(BDBConnectionTests) test_classes.append(BDBConnectionTests)
test_classes.append(BDBReconnectionTests)
def test_suite(): def test_suite():
......
...@@ -65,13 +65,14 @@ class ZEOTestServer(asyncore.dispatcher): ...@@ -65,13 +65,14 @@ class ZEOTestServer(asyncore.dispatcher):
""" """
__super_init = asyncore.dispatcher.__init__ __super_init = asyncore.dispatcher.__init__
def __init__(self, addr, storage): def __init__(self, addr, storage, keep):
self.__super_init() self.__super_init()
self.storage = storage self._storage = storage
self._keep = keep
# Count down to zero, the number of connects # Count down to zero, the number of connects
self.count = 1 self._count = 1
# For zLOG # For zLOG
self.label ='zeoserver:%d @ %s' % (os.getpid(), addr) self._label ='zeoserver:%d @ %s' % (os.getpid(), addr)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
# Some ZEO tests attempt a quick start of the server using the same # Some ZEO tests attempt a quick start of the server using the same
# port so we have to set the reuse flag. # port so we have to set the reuse flag.
...@@ -87,22 +88,23 @@ class ZEOTestServer(asyncore.dispatcher): ...@@ -87,22 +88,23 @@ class ZEOTestServer(asyncore.dispatcher):
self.log('bound and listening') self.log('bound and listening')
def log(self, msg, *args): def log(self, msg, *args):
log(self.label, msg, *args) log(self._label, msg, *args)
def handle_accept(self): def handle_accept(self):
sock, addr = self.accept() sock, addr = self.accept()
self.log('in handle_accept()') self.log('in handle_accept()')
# When we're done with everything, close the storage. Do not write # When we're done with everything, close the storage. Do not write
# the ack character until the storage is finished closing. # the ack character until the storage is finished closing.
if self.count <= 0: if self._count <= 0:
self.log('closing the storage') self.log('closing the storage')
self.storage.close() self._storage.close()
cleanup(self.storage) if not self._keep:
cleanup(self._storage)
self.log('exiting') self.log('exiting')
os._exit(0) os._exit(0)
self.log('continuing') self.log('continuing')
sock.send('X') sock.send('X')
self.count -= 1 self._count -= 1
def main(): def main():
...@@ -111,12 +113,15 @@ def main(): ...@@ -111,12 +113,15 @@ def main():
# We don't do much sanity checking of the arguments, since if we get it # We don't do much sanity checking of the arguments, since if we get it
# wrong, it's a bug in the test suite. # wrong, it's a bug in the test suite.
ro_svr = 0 ro_svr = 0
keep = 0
configfile = None configfile = None
# Parse the arguments and let getopt.error percolate # Parse the arguments and let getopt.error percolate
opts, args = getopt.getopt(sys.argv[1:], 'rC:') opts, args = getopt.getopt(sys.argv[1:], 'rkC:')
for opt, arg in opts: for opt, arg in opts:
if opt == '-r': if opt == '-r':
ro_svr = 1 ro_svr = 1
elif opt == '-k':
keep = 1
elif opt == '-C': elif opt == '-C':
configfile = arg configfile = arg
# Open the config file and let ZConfig parse the data there. Then remove # Open the config file and let ZConfig parse the data there. Then remove
...@@ -129,8 +134,8 @@ def main(): ...@@ -129,8 +134,8 @@ def main():
zeo_port = int(args[0]) zeo_port = int(args[0])
test_port = zeo_port + 1 test_port = zeo_port + 1
try: try:
log(label, 'creating the test server') log(label, 'creating the test server, ro: %s, keep: %s', ro_svr, keep)
t = ZEOTestServer(('', test_port), storage) t = ZEOTestServer(('', test_port), storage, keep)
except socket.error, e: except socket.error, e:
if e[0] <> errno.EADDRINUSE: raise if e[0] <> errno.EADDRINUSE: raise
log(label, 'addr in use, closing and exiting') log(label, 'addr in use, closing and exiting')
......
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