Commit b1bb01e2 authored by Guido van Rossum's avatar Guido van Rossum

Fix a race condition in this test -- instead of assuming that it will take

the test server thread at most 0.5 seconds to get ready, use an event
variable.
parent 06c65790
...@@ -74,6 +74,7 @@ class ServerThread(threading.Thread): ...@@ -74,6 +74,7 @@ class ServerThread(threading.Thread):
self.__addr = addr self.__addr = addr
self.__svrcls = svrcls self.__svrcls = svrcls
self.__hdlrcls = hdlrcls self.__hdlrcls = hdlrcls
self.ready = threading.Event()
def run(self): def run(self):
class svrcls(MyMixinServer, self.__svrcls): class svrcls(MyMixinServer, self.__svrcls):
pass pass
...@@ -87,6 +88,7 @@ class ServerThread(threading.Thread): ...@@ -87,6 +88,7 @@ class ServerThread(threading.Thread):
if self.__addr != svr.socket.getsockname(): if self.__addr != svr.socket.getsockname():
raise RuntimeError('server_address was %s, expected %s' % raise RuntimeError('server_address was %s, expected %s' %
(self.__addr, svr.socket.getsockname())) (self.__addr, svr.socket.getsockname()))
self.ready.set()
if verbose: print "thread: serving three times" if verbose: print "thread: serving three times"
svr.serve_a_few() svr.serve_a_few()
if verbose: print "thread: done" if verbose: print "thread: done"
...@@ -139,7 +141,9 @@ def testloop(proto, servers, hdlrcls, testfunc): ...@@ -139,7 +141,9 @@ def testloop(proto, servers, hdlrcls, testfunc):
t.start() t.start()
if verbose: print "server running" if verbose: print "server running"
for i in range(NREQ): for i in range(NREQ):
time.sleep(DELAY) t.ready.wait(10*DELAY)
if not t.ready.isSet():
raise RuntimeError("Server not ready within a reasonable time")
if verbose: print "test client", i if verbose: print "test client", i
testfunc(proto, addr) testfunc(proto, addr)
if verbose: print "waiting for server" if verbose: print "waiting for server"
......
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