mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix Issue8460: Victor's patch to add timeout in test_urllib2net test_urls.
This commit is contained in:
parent
ac4b7adadf
commit
281b551a2e
1 changed files with 16 additions and 4 deletions
|
@ -7,6 +7,9 @@ from test.test_urllib2 import sanepathname2url
|
||||||
import socket
|
import socket
|
||||||
import urllib2
|
import urllib2
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
TIMEOUT = 60 # seconds
|
||||||
|
|
||||||
|
|
||||||
def _retry_thrice(func, exc, *args, **kwargs):
|
def _retry_thrice(func, exc, *args, **kwargs):
|
||||||
|
@ -167,18 +170,27 @@ class OtherNetworkTests(unittest.TestCase):
|
||||||
req = expected_err = None
|
req = expected_err = None
|
||||||
debug(url)
|
debug(url)
|
||||||
try:
|
try:
|
||||||
f = urlopen(url, req)
|
f = urlopen(url, req, TIMEOUT)
|
||||||
except EnvironmentError, err:
|
except EnvironmentError, err:
|
||||||
debug(err)
|
debug(err)
|
||||||
if expected_err:
|
if expected_err:
|
||||||
msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
|
msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
|
||||||
(expected_err, url, req, type(err), err))
|
(expected_err, url, req, type(err), err))
|
||||||
self.assertIsInstance(err, expected_err, msg)
|
self.assertIsInstance(err, expected_err, msg)
|
||||||
|
except urllib2.URLError as err:
|
||||||
|
if isinstance(err[0], socket.timeout):
|
||||||
|
print >>sys.stderr, "<timeout: %s>" % url
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
with test_support.transient_internet():
|
try:
|
||||||
buf = f.read()
|
with test_support.transient_internet():
|
||||||
|
buf = f.read()
|
||||||
|
debug("read %d bytes" % len(buf))
|
||||||
|
except socket.timeout:
|
||||||
|
print >>sys.stderr, "<timeout: %s>" % url
|
||||||
f.close()
|
f.close()
|
||||||
debug("read %d bytes" % len(buf))
|
|
||||||
debug("******** next url coming up...")
|
debug("******** next url coming up...")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue