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