diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-26 04:55:51 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-26 04:55:51 (GMT) |
commit | 85fc3c1f1c6d0d38b3367a99a9e860639d4043e9 (patch) | |
tree | 2aa0664fb606f12e525f9a474d8b0f27bcd678da /Lib | |
parent | 7c29aaee88dab01530090a82c4cb17a506449aa1 (diff) | |
download | cpython-85fc3c1f1c6d0d38b3367a99a9e860639d4043e9.zip cpython-85fc3c1f1c6d0d38b3367a99a9e860639d4043e9.tar.gz cpython-85fc3c1f1c6d0d38b3367a99a9e860639d4043e9.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_timeout.py | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index da4602f..02687b0 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) |