[Python-checkins] r60337 - python/branches/release25-maint/Lib/test/test_support.py

neal.norwitz python-checkins at python.org
Sun Jan 27 02:24:44 CET 2008


Author: neal.norwitz
Date: Sun Jan 27 02:24:44 2008
New Revision: 60337

Modified:
   python/branches/release25-maint/Lib/test/test_support.py
Log:
Backport r58453:
Let the O/S supply a port if none of the default ports can be used.
This should make the tests more robust at the expense of allowing
tests to be sloppier by not requiring them to cleanup after themselves.
(It will legitamitely help when running two test suites simultaneously
or if another process is already using one of the predefined ports.)

This will hopefully fix test_asynchat.


Modified: python/branches/release25-maint/Lib/test/test_support.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_support.py	(original)
+++ python/branches/release25-maint/Lib/test/test_support.py	Sun Jan 27 02:24:44 2008
@@ -95,10 +95,20 @@
     makes the test more robust."""
 
     import socket, errno
-    # some random ports that hopefully no one is listening on.
-    for port in [preferred_port, 9907, 10243, 32999]:
+
+    # 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 [preferred_port, 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:


More information about the Python-checkins mailing list