From: Neal Norwitz Date: Wed, 26 Mar 2008 04:55:51 +0000 (+0000) Subject: Try to get this test to be less flaky. It was failing sometimes because X-Git-Tag: v2.6a2~108 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=85fc3c1f1c6d0d38b3367a99a9e860639d4043e9;p=python Try to get this test to be less flaky. It was failing sometimes because the connect would succeed before the timeout occurred. Try using an address and port that hopefully doesn't exist to ensure we get no response. If this doesn't work, we can use a public address close to python.org and hopefully that address never gets taken. --- diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index da4602f825..02687b0742 100644 --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -107,24 +107,19 @@ class TimeoutTestCase(unittest.TestCase): self.sock.close() def testConnectTimeout(self): - # If we are too close to www.python.org, this test will fail. - # Pick a host that should be farther away. - if (socket.getfqdn().split('.')[-2:] == ['python', 'org'] or - socket.getfqdn().split('.')[-2:-1] == ['xs4all']): - self.addr_remote = ('tut.fi', 80) - - # Lookup the IP address to avoid including the DNS lookup time + # Choose a private address that is unlikely to exist to prevent + # failures due to the connect succeeding before the timeout. + # Use a dotted IP address to avoid including the DNS lookup time # with the connect time. This avoids failing the assertion that # the timeout occurred fast enough. - self.addr_remote = (socket.gethostbyname(self.addr_remote[0]), 80) + addr = ('10.0.0.0', 12345) # Test connect() timeout _timeout = 0.001 self.sock.settimeout(_timeout) _t1 = time.time() - self.failUnlessRaises(socket.error, self.sock.connect, - self.addr_remote) + self.failUnlessRaises(socket.error, self.sock.connect, addr) _t2 = time.time() _delta = abs(_t1 - _t2)