]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #16257: make test_create_connection() handle ENETUNREACH.
authorTrent Nelson <trent@trent.me>
Thu, 18 Oct 2012 05:35:32 +0000 (01:35 -0400)
committerTrent Nelson <trent@trent.me>
Thu, 18 Oct 2012 05:35:32 +0000 (01:35 -0400)
Lib/test/test_socket.py

index 13d0eb4b8b5ddd762f71ae295dca96e37a6485bc..7d8b33a2ba4191c6e8e0bcb39c4917394c302f7b 100644 (file)
@@ -1197,7 +1197,26 @@ class NetworkConnectionNoServer(unittest.TestCase):
         port = test_support.find_unused_port()
         with self.assertRaises(socket.error) as cm:
             socket.create_connection((HOST, port))
-        self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)
+
+        # Issue #16257: create_connection() calls getaddrinfo() against
+        # 'localhost'.  This may result in an IPV6 addr being returned
+        # as well as an IPV4 one:
+        #   >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM)
+        #   >>> [(2,  2, 0, '', ('127.0.0.1', 41230)),
+        #        (26, 2, 0, '', ('::1', 41230, 0, 0))]
+        #
+        # create_connection() enumerates through all the addresses returned
+        # and if it doesn't successfully bind to any of them, it propagates
+        # the last exception it encountered.
+        #
+        # On Solaris, ENETUNREACH is returned in this circumstance instead
+        # of ECONNREFUSED.  So, if that errno exists, add it to our list of
+        # expected errnos.
+        expected_errnos = [ errno.ECONNREFUSED, ]
+        if hasattr(errno, 'ENETUNREACH'):
+            expected_errnos.append(errno.ENETUNREACH)
+
+        self.assertIn(cm.exception.errno, expected_errnos)
 
     def test_create_connection_timeout(self):
         # Issue #9792: create_connection() should not recast timeout errors