[Python-checkins] cpython (2.7): Fix test.test_support.bind_port() to not cause an error when Python was

gregory.p.smith python-checkins at python.org
Mon Nov 25 04:42:36 CET 2013


http://hg.python.org/cpython/rev/01788f8477a5
changeset:   87532:01788f8477a5
branch:      2.7
parent:      87529:9b170d74a0a2
user:        Gregory P. Smith <greg at krypto.org>
date:        Sun Nov 24 19:42:15 2013 -0800
summary:
  Fix test.test_support.bind_port() to not cause an error when Python was
compiled on a system with SO_REUSEPORT defined in the headers but run on
a system with an OS kernel that does not support that new socket option.

files:
  Lib/test/test_support.py |  12 +++++++++---
  Misc/NEWS                |   4 ++++
  2 files changed, 13 insertions(+), 3 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
@@ -409,9 +409,15 @@
                 raise TestFailed("tests should never set the SO_REUSEADDR "   \
                                  "socket option on TCP/IP sockets!")
         if hasattr(socket, 'SO_REUSEPORT'):
-            if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
-                raise TestFailed("tests should never set the SO_REUSEPORT "   \
-                                 "socket option on TCP/IP sockets!")
+            try:
+                if sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT) == 1:
+                    raise TestFailed("tests should never set the SO_REUSEPORT "   \
+                                     "socket option on TCP/IP sockets!")
+            except EnvironmentError:
+                # Python's socket module was compiled using modern headers
+                # thus defining SO_REUSEPORT but this process is running
+                # under an older kernel that does not support SO_REUSEPORT.
+                pass
         if hasattr(socket, 'SO_EXCLUSIVEADDRUSE'):
             sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1)
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@
 Library
 -------
 
+- Fix test.test_support.bind_port() to not cause an error when Python was
+  compiled on a system with SO_REUSEPORT defined in the headers but run on
+  a system with an OS kernel that does not support that new socket option.
+
 - Issue #19633: Fixed writing not compressed 16- and 32-bit wave files on
   big-endian platforms.
 

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


More information about the Python-checkins mailing list