119
119
"run_with_locale" , "swap_item" ,
120
120
"swap_attr" , "Matcher" , "set_memlimit" , "SuppressCrashReport" , "sortdict" ,
121
121
"run_with_tz" , "PGO" , "missing_compiler_executable" , "fd_count" ,
122
- "ALWAYS_EQ" , "NEVER_EQ" , "LARGEST" , "SMALLEST"
122
+ "ALWAYS_EQ" , "NEVER_EQ" , "LARGEST" , "SMALLEST" ,
123
+ "LOOPBACK_TIMEOUT" , "INTERNET_TIMEOUT" , "SHORT_TIMEOUT" , "LONG_TIMEOUT" ,
123
124
]
124
125
126
+
127
+ # Timeout in seconds for tests using a network server listening on the network
128
+ # local loopback interface like 127.0.0.1.
129
+ #
130
+ # The timeout is long enough to prevent test failure: it takes into account
131
+ # that the client and the server can run in different threads or even different
132
+ # processes.
133
+ #
134
+ # The timeout should be long enough for connect(), recv() and send() methods
135
+ # of socket.socket.
136
+ LOOPBACK_TIMEOUT = 5.0
137
+ if sys .platform == 'win32' and platform .machine () == 'ARM' :
138
+ # bpo-37553: test_socket.SendfileUsingSendTest is taking longer than 2
139
+ # seconds on Windows ARM32 buildbot
140
+ LOOPBACK_TIMEOUT = 10
141
+
142
+ # Timeout in seconds for network requests going to the Internet. The timeout is
143
+ # short enough to prevent a test to wait for too long if the Internet request
144
+ # is blocked for whatever reason.
145
+ #
146
+ # Usually, a timeout using INTERNET_TIMEOUT should not mark a test as failed,
147
+ # but skip the test instead: see transient_internet().
148
+ INTERNET_TIMEOUT = 60.0
149
+
150
+ # Timeout in seconds to mark a test as failed if the test takes "too long".
151
+ #
152
+ # The timeout value depends on the regrtest --timeout command line option.
153
+ #
154
+ # If a test using SHORT_TIMEOUT starts to fail randomly on slow buildbots, use
155
+ # LONG_TIMEOUT instead.
156
+ SHORT_TIMEOUT = 30.0
157
+
158
+ # Timeout in seconds to detect when a test hangs.
159
+ #
160
+ # It is long enough to reduce the risk of test failure on the slowest Python
161
+ # buildbots. It should not be used to mark a test as failed if the test takes
162
+ # "too long". The timeout value depends on the regrtest --timeout command line
163
+ # option.
164
+ LONG_TIMEOUT = 5 * 60.0
165
+
166
+ _NOT_SET = object ()
167
+
168
+
125
169
class Error (Exception ):
126
170
"""Base class for regression test exceptions."""
127
171
@@ -1231,7 +1275,7 @@ def check_valid_file(fn):
1231
1275
opener = urllib .request .build_opener ()
1232
1276
if gzip :
1233
1277
opener .addheaders .append (('Accept-Encoding' , 'gzip' ))
1234
- f = opener .open (url , timeout = 15 )
1278
+ f = opener .open (url , timeout = INTERNET_TIMEOUT )
1235
1279
if gzip and f .headers .get ('Content-Encoding' ) == 'gzip' :
1236
1280
f = gzip .GzipFile (fileobj = f )
1237
1281
try :
@@ -1542,9 +1586,12 @@ def get_socket_conn_refused_errs():
1542
1586
1543
1587
1544
1588
@contextlib .contextmanager
1545
- def transient_internet (resource_name , * , timeout = 30.0 , errnos = ()):
1589
+ def transient_internet (resource_name , * , timeout = _NOT_SET , errnos = ()):
1546
1590
"""Return a context manager that raises ResourceDenied when various issues
1547
1591
with the Internet connection manifest themselves as exceptions."""
1592
+ if timeout is _NOT_SET :
1593
+ timeout = INTERNET_TIMEOUT
1594
+
1548
1595
default_errnos = [
1549
1596
('ECONNREFUSED' , 111 ),
1550
1597
('ECONNRESET' , 104 ),
@@ -2264,7 +2311,7 @@ def decorator(*args):
2264
2311
2265
2312
2266
2313
@contextlib .contextmanager
2267
- def wait_threads_exit (timeout = 60.0 ):
2314
+ def wait_threads_exit (timeout = None ):
2268
2315
"""
2269
2316
bpo-31234: Context manager to wait until all threads created in the with
2270
2317
statement exit.
@@ -2278,6 +2325,8 @@ def wait_threads_exit(timeout=60.0):
2278
2325
which doesn't allow to wait for thread exit, whereas thread.Thread has a
2279
2326
join() method.
2280
2327
"""
2328
+ if timeout is None :
2329
+ timeout = SHORT_TIMEOUT
2281
2330
old_count = _thread ._count ()
2282
2331
try :
2283
2332
yield
@@ -2298,10 +2347,12 @@ def wait_threads_exit(timeout=60.0):
2298
2347
gc_collect ()
2299
2348
2300
2349
2301
- def join_thread (thread , timeout = 30.0 ):
2350
+ def join_thread (thread , timeout = None ):
2302
2351
"""Join a thread. Raise an AssertionError if the thread is still alive
2303
2352
after timeout seconds.
2304
2353
"""
2354
+ if timeout is None :
2355
+ timeout = SHORT_TIMEOUT
2305
2356
thread .join (timeout )
2306
2357
if thread .is_alive ():
2307
2358
msg = f"failed to join the thread in { timeout :.1f} seconds"
0 commit comments