Skip to content

Commit 4bcfa3a

Browse files
authored
bpo-30131: Cleanup threads in test_logging (python#1275)
* Use @support.reap_threads on unit tests creating threads * Call TestCase.fail() on thread.join(timeout) failure
1 parent fcfe80e commit 4bcfa3a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Lib/test/test_logging.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ def test_path_objects(self):
619619

620620
@unittest.skipIf(os.name == 'nt', 'WatchedFileHandler not appropriate for Windows.')
621621
@unittest.skipUnless(threading, 'Threading required for this test.')
622+
@support.reap_threads
622623
def test_race(self):
623624
# Issue #14632 refers.
624625
def remove_loop(fname, tries):
@@ -776,7 +777,10 @@ def stop(self, timeout=None):
776777
"""
777778
self.close()
778779
self._thread.join(timeout)
780+
alive = self._thread.is_alive()
779781
self._thread = None
782+
if alive:
783+
self.fail("join() timed out")
780784

781785
class ControlMixin(object):
782786
"""
@@ -827,7 +831,10 @@ def stop(self, timeout=None):
827831
self.shutdown()
828832
if self._thread is not None:
829833
self._thread.join(timeout)
834+
alive = self._thread.is_alive()
830835
self._thread = None
836+
if alive:
837+
self.fail("join() timed out")
831838
self.server_close()
832839
self.ready.clear()
833840

@@ -962,6 +969,8 @@ class TestUnixDatagramServer(TestUDPServer):
962969
@unittest.skipUnless(threading, 'Threading required for this test.')
963970
class SMTPHandlerTest(BaseTest):
964971
TIMEOUT = 8.0
972+
973+
@support.reap_threads
965974
def test_basic(self):
966975
sockmap = {}
967976
server = TestSMTPServer((support.HOST, 0), self.process_message, 0.001,
@@ -1752,6 +1761,7 @@ def handle_request(self, request):
17521761
request.end_headers()
17531762
self.handled.set()
17541763

1764+
@support.reap_threads
17551765
def test_output(self):
17561766
# The log message sent to the HTTPHandler is properly received.
17571767
logger = logging.getLogger("http")
@@ -2863,8 +2873,11 @@ def setup_via_listener(self, text, verify=None):
28632873
t.ready.wait(2.0)
28642874
logging.config.stopListening()
28652875
t.join(2.0)
2876+
if t.is_alive():
2877+
self.fail("join() timed out")
28662878

28672879
@unittest.skipUnless(threading, 'Threading required for this test.')
2880+
@support.reap_threads
28682881
def test_listen_config_10_ok(self):
28692882
with support.captured_stdout() as output:
28702883
self.setup_via_listener(json.dumps(self.config10))
@@ -2885,6 +2898,7 @@ def test_listen_config_10_ok(self):
28852898
], stream=output)
28862899

28872900
@unittest.skipUnless(threading, 'Threading required for this test.')
2901+
@support.reap_threads
28882902
def test_listen_config_1_ok(self):
28892903
with support.captured_stdout() as output:
28902904
self.setup_via_listener(textwrap.dedent(ConfigFileTest.config1))
@@ -2900,6 +2914,7 @@ def test_listen_config_1_ok(self):
29002914
self.assert_log_lines([])
29012915

29022916
@unittest.skipUnless(threading, 'Threading required for this test.')
2917+
@support.reap_threads
29032918
def test_listen_verify(self):
29042919

29052920
def verify_fail(stuff):

0 commit comments

Comments
 (0)