Charles-François Natali added the comment:

Here's an updated patch using the lru_cache decorator.

----------
Added file: http://bugs.python.org/file31312/connect_timeout-1.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16463>
_______________________________________
diff -r 928d405fe2ad Lib/test/test_timeout.py
--- a/Lib/test/test_timeout.py  Sun Aug 04 15:35:57 2013 +0200
+++ b/Lib/test/test_timeout.py  Fri Aug 16 13:50:31 2013 +0200
@@ -1,5 +1,6 @@
 """Unit tests for socket timeout feature."""
 
+import functools
 import unittest
 from test import support
 
@@ -126,13 +127,24 @@
         self.assertLess(delta, timeout + self.fuzz)
         self.assertGreater(delta, timeout - 1.0)
 
+    @functools.lru_cache()
+    def resolve_address(self, host, port):
+        """Resolve an (host, port) to an address.
+
+        We must perform name resolution before timeout tests, otherwise it will
+        be performed by connect().
+        """
+        with support.transient_internet(host):
+            return socket.getaddrinfo(host, port, socket.AF_INET,
+                                      socket.SOCK_STREAM)[0][4]
+
 
 class TCPTimeoutTestCase(TimeoutTestCase):
     """TCP test case for socket.socket() timeout functions"""
 
     def setUp(self):
         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.addr_remote = ('www.python.org.', 80)
+        self.addr_remote = self.resolve_address('www.python.org.', 80)
 
     def tearDown(self):
         self.sock.close()
@@ -142,7 +154,7 @@
         # to a host that silently drops our packets.  We can't simulate this
         # from Python because it's a function of the underlying TCP/IP stack.
         # So, the following Snakebite host has been defined:
-        blackhole = ('blackhole.snakebite.net', 56666)
+        blackhole = self.resolve_address('blackhole.snakebite.net', 56666)
 
         # Blackhole has been configured to silently drop any incoming packets.
         # No RSTs (for TCP) or ICMP UNREACH (for UDP/ICMP) will be sent back
@@ -154,7 +166,7 @@
         # to firewalling or general network configuration.  In order to improve
         # our confidence in testing the blackhole, a corresponding 'whitehole'
         # has also been set up using one port higher:
-        whitehole = ('whitehole.snakebite.net', 56667)
+        whitehole = self.resolve_address('whitehole.snakebite.net', 56667)
 
         # This address has been configured to immediately drop any incoming
         # packets as well, but it does it respectfully with regards to the
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to