Commit 0d767328 authored by Jeremy Hylton's avatar Jeremy Hylton

Backport changes from ZODB4.

Explicitly close sockets to make tests run faster.
parent f556d60e
...@@ -91,17 +91,20 @@ def start_zeo_server(conf, addr=None, ro_svr=0, monitor=0, keep=0, invq=None, ...@@ -91,17 +91,20 @@ def start_zeo_server(conf, addr=None, ro_svr=0, monitor=0, keep=0, invq=None,
pid = os.spawnve(os.P_NOWAIT, sys.executable, tuple(args), d) pid = os.spawnve(os.P_NOWAIT, sys.executable, tuple(args), d)
adminaddr = ('localhost', port+1) adminaddr = ('localhost', port+1)
# We need to wait until the server starts, but not forever # We need to wait until the server starts, but not forever
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) for i in range(10):
for i in range(5): time.sleep(0.25)
try: try:
zLOG.LOG('forker', zLOG.DEBUG, 'connect %s' % i) zLOG.LOG('forker', zLOG.DEBUG, 'connect %s' % i)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(adminaddr) s.connect(adminaddr)
ack = s.recv(1024) ack = s.recv(1024)
s.close()
zLOG.LOG('forker', zLOG.DEBUG, 'acked: %s' % ack) zLOG.LOG('forker', zLOG.DEBUG, 'acked: %s' % ack)
break break
except socket.error, e: except socket.error, e:
if e[0] <> errno.ECONNREFUSED: raise if e[0] not in (errno.ECONNREFUSED, errno.ECONNRESET):
time.sleep(1) raise
s.close()
else: else:
zLOG.LOG('forker', zLOG.DEBUG, 'boo hoo') zLOG.LOG('forker', zLOG.DEBUG, 'boo hoo')
raise raise
......
...@@ -71,6 +71,7 @@ class ZEOTestServer(asyncore.dispatcher): ...@@ -71,6 +71,7 @@ class ZEOTestServer(asyncore.dispatcher):
def __init__(self, addr, server, keep): def __init__(self, addr, server, keep):
self.__super_init() self.__super_init()
self._server = server self._server = server
self._sockets = [self]
self._keep = keep 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
...@@ -105,11 +106,22 @@ class ZEOTestServer(asyncore.dispatcher): ...@@ -105,11 +106,22 @@ class ZEOTestServer(asyncore.dispatcher):
for storage in self._server.storages.values(): for storage in self._server.storages.values():
cleanup(storage) cleanup(storage)
self.log('exiting') self.log('exiting')
# Close all the other sockets so that we don't have to wait
# for os._exit() to get to it before starting the next
# server process.
for s in self._sockets:
s.close()
# Now explicitly close the socket returned from accept(),
# since it didn't go through the wrapper.
sock.close()
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 register_socket(self, sock):
# Register a socket to be closed when server shutsdown.
self._sockets.append(sock)
class Suicide(threading.Thread): class Suicide(threading.Thread):
def __init__(self, addr): def __init__(self, addr):
...@@ -118,7 +130,8 @@ class Suicide(threading.Thread): ...@@ -118,7 +130,8 @@ class Suicide(threading.Thread):
def run(self): def run(self):
# If this process doesn't exit in 60 seconds, commit suicide # If this process doesn't exit in 60 seconds, commit suicide
time.sleep(60) for i in range(20):
time.sleep(5)
from ZEO.tests.forker import shutdown_zeo_server from ZEO.tests.forker import shutdown_zeo_server
# XXX If the -k option was given to zeoserver, then the process will # XXX If the -k option was given to zeoserver, then the process will
# go away but the temp files won't get cleaned up. # go away but the temp files won't get cleaned up.
...@@ -177,6 +190,7 @@ def main(): ...@@ -177,6 +190,7 @@ def main():
storage.close() storage.close()
cleanup(storage) cleanup(storage)
sys.exit(2) sys.exit(2)
t.register_socket(serv.dispatcher)
# Create daemon suicide thread # Create daemon suicide thread
d = Suicide(test_addr) d = Suicide(test_addr)
d.setDaemon(1) d.setDaemon(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