Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbc8b79

Browse files
authored
bpo-38614: Use default join_thread() timeout in tests (GH-17559)
Tests no longer pass a timeout value to join_thread() of test.support: use the default join_thread() timeout instead (SHORT_TIMEOUT constant of test.support).
1 parent 07871b2 commit bbc8b79

File tree

7 files changed

+26
-34
lines changed

7 files changed

+26
-34
lines changed

Lib/test/test_asynchat.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
HOST = support.HOST
1616
SERVER_QUIT = b'QUIT\n'
17-
TIMEOUT = 3.0
1817

1918

2019
class echo_server(threading.Thread):
@@ -122,7 +121,7 @@ def line_terminator_check(self, term, server_chunk):
122121
c.push(b"I'm not dead yet!" + term)
123122
c.push(SERVER_QUIT)
124123
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
125-
support.join_thread(s, timeout=TIMEOUT)
124+
support.join_thread(s)
126125

127126
self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
128127

@@ -153,7 +152,7 @@ def numeric_terminator_check(self, termlen):
153152
c.push(data)
154153
c.push(SERVER_QUIT)
155154
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
156-
support.join_thread(s, timeout=TIMEOUT)
155+
support.join_thread(s)
157156

158157
self.assertEqual(c.contents, [data[:termlen]])
159158

@@ -173,7 +172,7 @@ def test_none_terminator(self):
173172
c.push(data)
174173
c.push(SERVER_QUIT)
175174
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
176-
support.join_thread(s, timeout=TIMEOUT)
175+
support.join_thread(s)
177176

178177
self.assertEqual(c.contents, [])
179178
self.assertEqual(c.buffer, data)
@@ -185,7 +184,7 @@ def test_simple_producer(self):
185184
p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8)
186185
c.push_with_producer(p)
187186
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
188-
support.join_thread(s, timeout=TIMEOUT)
187+
support.join_thread(s)
189188

190189
self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
191190

@@ -195,7 +194,7 @@ def test_string_producer(self):
195194
data = b"hello world\nI'm not dead yet!\n"
196195
c.push_with_producer(data+SERVER_QUIT)
197196
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
198-
support.join_thread(s, timeout=TIMEOUT)
197+
support.join_thread(s)
199198

200199
self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])
201200

@@ -206,7 +205,7 @@ def test_empty_line(self):
206205
c.push(b"hello world\n\nI'm not dead yet!\n")
207206
c.push(SERVER_QUIT)
208207
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
209-
support.join_thread(s, timeout=TIMEOUT)
208+
support.join_thread(s)
210209

211210
self.assertEqual(c.contents,
212211
[b"hello world", b"", b"I'm not dead yet!"])
@@ -225,7 +224,7 @@ def test_close_when_done(self):
225224
# where the server echoes all of its data before we can check that it
226225
# got any down below.
227226
s.start_resend_event.set()
228-
support.join_thread(s, timeout=TIMEOUT)
227+
support.join_thread(s)
229228

230229
self.assertEqual(c.contents, [])
231230
# the server might have been able to send a byte or two back, but this
@@ -246,7 +245,7 @@ def test_push(self):
246245
self.assertRaises(TypeError, c.push, 'unicode')
247246
c.push(SERVER_QUIT)
248247
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
249-
support.join_thread(s, timeout=TIMEOUT)
248+
support.join_thread(s)
250249
self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes'])
251250

252251

Lib/test/test_asyncio/test_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def client():
699699
proto.transport.close()
700700
lsock.close()
701701

702-
support.join_thread(thread, timeout=1)
702+
support.join_thread(thread)
703703
self.assertFalse(thread.is_alive())
704704
self.assertEqual(proto.state, 'CLOSED')
705705
self.assertEqual(proto.nbytes, len(message))

Lib/test/test_asyncore.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
raise unittest.SkipTest("test is not helpful for PGO")
1717

1818

19-
TIMEOUT = 3
2019
HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX')
2120

2221
class dummysocket:
@@ -360,7 +359,7 @@ def test_send(self):
360359

361360
self.assertEqual(cap.getvalue(), data*2)
362361
finally:
363-
support.join_thread(t, timeout=TIMEOUT)
362+
support.join_thread(t)
364363

365364

366365
@unittest.skipUnless(hasattr(asyncore, 'file_wrapper'),
@@ -788,7 +787,7 @@ def test_quick_connect(self):
788787
except OSError:
789788
pass
790789
finally:
791-
support.join_thread(t, timeout=TIMEOUT)
790+
support.join_thread(t)
792791

793792
class TestAPI_UseIPv4Sockets(BaseTestAPI):
794793
family = socket.AF_INET

Lib/test/test_imaplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def _cleanup(self):
238238
# cleanup the server
239239
self.server.shutdown()
240240
self.server.server_close()
241-
support.join_thread(self.thread, 3.0)
241+
support.join_thread(self.thread)
242242
# Explicitly clear the attribute to prevent dangling thread
243243
self.thread = None
244244

Lib/test/test_logging.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -869,16 +869,13 @@ def serve_forever(self, poll_interval):
869869
"""
870870
asyncore.loop(poll_interval, map=self._map)
871871

872-
def stop(self, timeout=None):
872+
def stop(self):
873873
"""
874874
Stop the thread by closing the server instance.
875875
Wait for the server thread to terminate.
876-
877-
:param timeout: How long to wait for the server thread
878-
to terminate.
879876
"""
880877
self.close()
881-
support.join_thread(self._thread, timeout)
878+
support.join_thread(self._thread)
882879
self._thread = None
883880
asyncore.close_all(map=self._map, ignore_all=True)
884881

@@ -922,16 +919,13 @@ def serve_forever(self, poll_interval):
922919
self.ready.set()
923920
super(ControlMixin, self).serve_forever(poll_interval)
924921

925-
def stop(self, timeout=None):
922+
def stop(self):
926923
"""
927924
Tell the server thread to stop, and wait for it to do so.
928-
929-
:param timeout: How long to wait for the server thread
930-
to terminate.
931925
"""
932926
self.shutdown()
933927
if self._thread is not None:
934-
support.join_thread(self._thread, timeout)
928+
support.join_thread(self._thread)
935929
self._thread = None
936930
self.server_close()
937931
self.ready.clear()
@@ -1699,7 +1693,7 @@ def tearDown(self):
16991693
self.root_logger.removeHandler(self.sock_hdlr)
17001694
self.sock_hdlr.close()
17011695
if self.server:
1702-
self.server.stop(2.0)
1696+
self.server.stop()
17031697
finally:
17041698
BaseTest.tearDown(self)
17051699

@@ -1736,7 +1730,7 @@ def test_noserver(self):
17361730
# one-second timeout on socket.create_connection() (issue #16264).
17371731
self.sock_hdlr.retryStart = 2.5
17381732
# Kill the server
1739-
self.server.stop(2.0)
1733+
self.server.stop()
17401734
# The logging call should try to connect, which should fail
17411735
try:
17421736
raise RuntimeError('Deliberate mistake')
@@ -1810,7 +1804,7 @@ def tearDown(self):
18101804
"""Shutdown the UDP server."""
18111805
try:
18121806
if self.server:
1813-
self.server.stop(2.0)
1807+
self.server.stop()
18141808
if self.sock_hdlr:
18151809
self.root_logger.removeHandler(self.sock_hdlr)
18161810
self.sock_hdlr.close()
@@ -1891,7 +1885,7 @@ def tearDown(self):
18911885
"""Shutdown the server."""
18921886
try:
18931887
if self.server:
1894-
self.server.stop(2.0)
1888+
self.server.stop()
18951889
if self.sl_hdlr:
18961890
self.root_logger.removeHandler(self.sl_hdlr)
18971891
self.sl_hdlr.close()
@@ -2028,7 +2022,7 @@ def test_output(self):
20282022
self.assertEqual(d['funcName'], ['test_output'])
20292023
self.assertEqual(d['msg'], [msg])
20302024

2031-
self.server.stop(2.0)
2025+
self.server.stop()
20322026
self.root_logger.removeHandler(self.h_hdlr)
20332027
self.h_hdlr.close()
20342028

@@ -3228,7 +3222,7 @@ def setup_via_listener(self, text, verify=None):
32283222
finally:
32293223
t.ready.wait(2.0)
32303224
logging.config.stopListening()
3231-
support.join_thread(t, 2.0)
3225+
support.join_thread(t)
32323226

32333227
def test_listen_config_10_ok(self):
32343228
with support.captured_stdout() as output:

Lib/test/test_queue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def do_blocking_test(self, block_func, block_args, trigger_func, trigger_args):
6363
block_func)
6464
return self.result
6565
finally:
66-
support.join_thread(thread, 10) # make sure the thread terminates
66+
support.join_thread(thread) # make sure the thread terminates
6767

6868
# Call this instead if block_func is supposed to raise an exception.
6969
def do_exceptional_blocking_test(self,block_func, block_args, trigger_func,
@@ -79,7 +79,7 @@ def do_exceptional_blocking_test(self,block_func, block_args, trigger_func,
7979
self.fail("expected exception of kind %r" %
8080
expected_exception_class)
8181
finally:
82-
support.join_thread(thread, 10) # make sure the thread terminates
82+
support.join_thread(thread) # make sure the thread terminates
8383
if not thread.startedEvent.is_set():
8484
self.fail("trigger thread ended but event never set")
8585

Lib/test/test_sched.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_enter_concurrent(self):
8282
self.assertEqual(q.get(timeout=TIMEOUT), 5)
8383
self.assertTrue(q.empty())
8484
timer.advance(1000)
85-
support.join_thread(t, timeout=TIMEOUT)
85+
support.join_thread(t)
8686
self.assertTrue(q.empty())
8787
self.assertEqual(timer.time(), 5)
8888

@@ -137,7 +137,7 @@ def test_cancel_concurrent(self):
137137
self.assertEqual(q.get(timeout=TIMEOUT), 4)
138138
self.assertTrue(q.empty())
139139
timer.advance(1000)
140-
support.join_thread(t, timeout=TIMEOUT)
140+
support.join_thread(t)
141141
self.assertTrue(q.empty())
142142
self.assertEqual(timer.time(), 4)
143143

0 commit comments

Comments
 (0)