[Jython-checkins] jython (merge default -> default): Merged

jim.baker jython-checkins at python.org
Sat Jun 14 22:58:22 CEST 2014


http://hg.python.org/jython/rev/67a4b9a0361c
changeset:   7296:67a4b9a0361c
parent:      7294:759e56cfcac7
parent:      7295:2bddcf5b03b2
user:        Jim Baker <jim.baker at rackspace.com>
date:        Sat Jun 14 14:58:00 2014 -0600
summary:
  Merged https://bitbucket.org/jython/jython/pull-request/18/fixes-test_httplib-sourceaddresstest

files:
  Lib/test/test_support.py |  33 ++++++++++-----------------
  1 files changed, 12 insertions(+), 21 deletions(-)


diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -374,27 +374,18 @@
     from bind()'ing to our host/port for the duration of the test.
     """
     if is_jython:
-        # Find some random ports that hopefully no one is listening on.
-        # Ideally each test would clean up after itself and not continue
-        # listening on any ports.  However, this isn't the case.  The last port
-        # (0) is a stop-gap that asks the O/S to assign a port.  Whenever the
-        # warning message below is printed, the test that is listening on the
-        # port should be fixed to close the socket at the end of the test.
-        # Another reason why we can't use a port is another process (possibly
-        # another instance of the test suite) is using the same port.
-
-        for port in [54321, 9907, 10243, 32999, 0]:
-            try:
-                sock.bind((host, port))
-                if port == 0:
-                    port = sock.getsockname()[1]
-                return port
-            except socket.error, (err, msg):
-                if err != errno.EADDRINUSE:
-                    raise
-                print >>sys.__stderr__, \
-                    '  WARNING: failed to listen on port %d, trying another' % port
-        raise TestFailed, 'unable to find port to listen on'
+        # Late binding of the jython socket implementation to a
+        # ServerSocketChannel or SocketChannel means that it's not possible to
+        # get the port until a call to connect() or listen(). Hence why a new
+        # socket is created and listen() is called on it.
+        tempsock = socket.socket(sock.family, sock.type)
+        tempsock.bind((host, 0))
+        tempsock.listen(1)
+        port = tempsock.getsockname()[1]
+        tempsock.close()
+        del tempsock
+        sock.bind((host, port))
+        return port
 
     elif sock.family == socket.AF_INET and sock.type == socket.SOCK_STREAM:
         if hasattr(socket, 'SO_REUSEADDR'):

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list