[Python-checkins] r61776 - python/trunk/Lib/test/test_timeout.py
neal.norwitz
python-checkins at python.org
Sun Mar 23 04:43:34 CET 2008
Author: neal.norwitz
Date: Sun Mar 23 04:43:33 2008
New Revision: 61776
Modified:
python/trunk/Lib/test/test_timeout.py
Log:
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.
Modified: python/trunk/Lib/test/test_timeout.py
==============================================================================
--- python/trunk/Lib/test/test_timeout.py (original)
+++ python/trunk/Lib/test/test_timeout.py Sun Mar 23 04:43:33 2008
@@ -107,16 +107,21 @@
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)
More information about the Python-checkins
mailing list