From 83432babfd244f88a6fd7f336cfdb038fde5c4e8 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 29 Oct 2010 18:15:33 +0000 Subject: [PATCH] Issue #7547: fix transient failures due to network glitches in test_timeout. Patch by Sandro Tosi. --- Lib/test/test_timeout.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index b67cbc92f2..bbcdc25672 100644 --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -130,17 +130,19 @@ class TimeoutTestCase(unittest.TestCase): def testRecvTimeout(self): # Test recv() timeout _timeout = 0.02 - self.sock.connect(self.addr_remote) - self.sock.settimeout(_timeout) - _t1 = time.time() - self.assertRaises(socket.error, self.sock.recv, 1024) - _t2 = time.time() + with support.transient_internet(self.addr_remote[0]): + self.sock.connect(self.addr_remote) + self.sock.settimeout(_timeout) - _delta = abs(_t1 - _t2) - self.assertTrue(_delta < _timeout + self.fuzz, - "timeout (%g) is %g seconds more than expected (%g)" - %(_delta, self.fuzz, _timeout)) + _t1 = time.time() + self.assertRaises(socket.timeout, self.sock.recv, 1024) + _t2 = time.time() + + _delta = abs(_t1 - _t2) + self.assertTrue(_delta < _timeout + self.fuzz, + "timeout (%g) is %g seconds more than expected (%g)" + %(_delta, self.fuzz, _timeout)) def testAcceptTimeout(self): # Test accept() timeout -- 2.40.0