diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-27 08:40:51 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-27 08:40:51 (GMT) |
commit | 150acda57fabfa941d2ed5d5e8ab3e49dac9a73e (patch) | |
tree | 3955e5d3da94b27113b283a87bd136b4b3cca438 | |
parent | 47b5440f439b983cdcee1f52bb219977c3257e57 (diff) | |
download | cpython-150acda57fabfa941d2ed5d5e8ab3e49dac9a73e.zip cpython-150acda57fabfa941d2ed5d5e8ab3e49dac9a73e.tar.gz cpython-150acda57fabfa941d2ed5d5e8ab3e49dac9a73e.tar.bz2 |
Remove uses of find_unused_port() in test_ssl, and small cleanups
-rw-r--r-- | Lib/test/test_ssl.py | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index bbccaeb..ebb556b 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -696,9 +696,9 @@ else: self.flag = None self.active = False self.RootedHTTPRequestHandler.root = os.path.split(CERTFILE)[0] - self.port = test_support.find_unused_port() self.server = self.HTTPSServer( - (HOST, self.port), self.RootedHTTPRequestHandler, certfile) + (HOST, 0), self.RootedHTTPRequestHandler, certfile) + self.port = self.server.server_port threading.Thread.__init__(self) self.daemon = True @@ -851,28 +851,28 @@ else: listener_ready = threading.Event() listener_gone = threading.Event() - port = test_support.find_unused_port() - # `listener` runs in a thread. It opens a socket listening on - # PORT, and sits in an accept() until the main thread connects. - # Then it rudely closes the socket, and sets Event `listener_gone` - # to let the main thread know the socket is gone. + s = socket.socket() + port = test_support.bind_port(s, HOST) + + # `listener` runs in a thread. It sits in an accept() until + # the main thread connects. Then it rudely closes the socket, + # and sets Event `listener_gone` to let the main thread know + # the socket is gone. def listener(): - s = socket.socket() - s.bind((HOST, port)) s.listen(5) listener_ready.set() s.accept() - s = None # reclaim the socket object, which also closes it + s.close() listener_gone.set() def connector(): listener_ready.wait() - s = socket.socket() - s.connect((HOST, port)) + c = socket.socket() + c.connect((HOST, port)) listener_gone.wait() try: - ssl_sock = ssl.wrap_socket(s) + ssl_sock = ssl.wrap_socket(c) except IOError: pass else: @@ -881,8 +881,10 @@ else: t = threading.Thread(target=listener) t.start() - connector() - t.join() + try: + connector() + finally: + t.join() def testEcho (self): @@ -1354,10 +1356,6 @@ def test_main(verbose=False): not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT)): raise test_support.TestFailed("Can't read certificate files!") - TESTPORT = test_support.find_unused_port() - if not TESTPORT: - raise test_support.TestFailed("Can't find open port to test servers on!") - tests = [BasicTests] if test_support.is_resource_enabled('network'): |