mirror of https://github.com/python/cpython.git
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.
This commit is contained in:
parent
7c29aaee88
commit
85fc3c1f1c
|
@ -107,24 +107,19 @@ def tearDown(self):
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue