diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-23 03:43:33 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2008-03-23 03:43:33 (GMT) |
commit | 1f2995b014f609c01f42aaa1409c5c7757b9641c (patch) | |
tree | 7d178ddd759cb4087f879f2940c056e551185e52 /Lib/test/test_timeout.py | |
parent | e70bb8d6f25b5e9aa0b3221943e302392023d164 (diff) | |
download | cpython-1f2995b014f609c01f42aaa1409c5c7757b9641c.zip cpython-1f2995b014f609c01f42aaa1409c5c7757b9641c.tar.gz cpython-1f2995b014f609c01f42aaa1409c5c7757b9641c.tar.bz2 |
Try to make this test a little more robust and not fail with:
timeout (10.0025) is more than 2 seconds more than expected (0.001)
I'm assuming this problem is caused by DNS lookup. This change
does a DNS lookup of the hostname before trying to connect, so the time
is not included.
Diffstat (limited to 'Lib/test/test_timeout.py')
-rw-r--r-- | Lib/test/test_timeout.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index 2b32b92..da4602f 100644 --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -107,16 +107,21 @@ class TimeoutTestCase(unittest.TestCase): self.sock.close() def testConnectTimeout(self): - # Test connect() timeout - _timeout = 0.001 - self.sock.settimeout(_timeout) - # 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 + # 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) + + # Test connect() timeout + _timeout = 0.001 + self.sock.settimeout(_timeout) + _t1 = time.time() self.failUnlessRaises(socket.error, self.sock.connect, self.addr_remote) |