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:
Neal Norwitz 2008-03-26 04:55:51 +00:00
parent 7c29aaee88
commit 85fc3c1f1c
1 changed files with 5 additions and 10 deletions

View File

@ -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)