Kaydet (Commit) 85fc3c1f authored tarafından Neal Norwitz's avatar Neal Norwitz

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.
üst 7c29aaee
...@@ -107,24 +107,19 @@ class TimeoutTestCase(unittest.TestCase): ...@@ -107,24 +107,19 @@ class TimeoutTestCase(unittest.TestCase):
self.sock.close() self.sock.close()
def testConnectTimeout(self): def testConnectTimeout(self):
# If we are too close to www.python.org, this test will fail. # Choose a private address that is unlikely to exist to prevent
# Pick a host that should be farther away. # failures due to the connect succeeding before the timeout.
if (socket.getfqdn().split('.')[-2:] == ['python', 'org'] or # Use a dotted IP address to avoid including the DNS lookup time
socket.getfqdn().split('.')[-2:-1] == ['xs4all']):
self.addr_remote = ('tut.fi', 80)
# Lookup the IP address to avoid including the DNS lookup time
# with the connect time. This avoids failing the assertion that # with the connect time. This avoids failing the assertion that
# the timeout occurred fast enough. # the timeout occurred fast enough.
self.addr_remote = (socket.gethostbyname(self.addr_remote[0]), 80) addr = ('10.0.0.0', 12345)
# Test connect() timeout # Test connect() timeout
_timeout = 0.001 _timeout = 0.001
self.sock.settimeout(_timeout) self.sock.settimeout(_timeout)
_t1 = time.time() _t1 = time.time()
self.failUnlessRaises(socket.error, self.sock.connect, self.failUnlessRaises(socket.error, self.sock.connect, addr)
self.addr_remote)
_t2 = time.time() _t2 = time.time()
_delta = abs(_t1 - _t2) _delta = abs(_t1 - _t2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment