summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_logging.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-04-24 22:41:36 (GMT)
committerGitHub <noreply@github.com>2017-04-24 22:41:36 (GMT)
commit4bcfa3a2363c30d406c6826e291b30c33a649d18 (patch)
treedc68406bf769cab055c3956f08029aab669bda6a /Lib/test/test_logging.py
parentfcfe80ec2592fed8b3941c79056a8737abef7d3b (diff)
downloadcpython-4bcfa3a2363c30d406c6826e291b30c33a649d18.zip
cpython-4bcfa3a2363c30d406c6826e291b30c33a649d18.tar.gz
cpython-4bcfa3a2363c30d406c6826e291b30c33a649d18.tar.bz2
bpo-30131: Cleanup threads in test_logging (#1275)
* Use @support.reap_threads on unit tests creating threads * Call TestCase.fail() on thread.join(timeout) failure
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r--Lib/test/test_logging.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 9f482e1..ca7a774 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -619,6 +619,7 @@ class HandlerTest(BaseTest):
@unittest.skipIf(os.name == 'nt', 'WatchedFileHandler not appropriate for Windows.')
@unittest.skipUnless(threading, 'Threading required for this test.')
+ @support.reap_threads
def test_race(self):
# Issue #14632 refers.
def remove_loop(fname, tries):
@@ -776,7 +777,10 @@ if threading:
"""
self.close()
self._thread.join(timeout)
+ alive = self._thread.is_alive()
self._thread = None
+ if alive:
+ self.fail("join() timed out")
class ControlMixin(object):
"""
@@ -827,7 +831,10 @@ if threading:
self.shutdown()
if self._thread is not None:
self._thread.join(timeout)
+ alive = self._thread.is_alive()
self._thread = None
+ if alive:
+ self.fail("join() timed out")
self.server_close()
self.ready.clear()
@@ -962,6 +969,8 @@ if threading:
@unittest.skipUnless(threading, 'Threading required for this test.')
class SMTPHandlerTest(BaseTest):
TIMEOUT = 8.0
+
+ @support.reap_threads
def test_basic(self):
sockmap = {}
server = TestSMTPServer((support.HOST, 0), self.process_message, 0.001,
@@ -1752,6 +1761,7 @@ class HTTPHandlerTest(BaseTest):
request.end_headers()
self.handled.set()
+ @support.reap_threads
def test_output(self):
# The log message sent to the HTTPHandler is properly received.
logger = logging.getLogger("http")
@@ -2863,8 +2873,11 @@ class ConfigDictTest(BaseTest):
t.ready.wait(2.0)
logging.config.stopListening()
t.join(2.0)
+ if t.is_alive():
+ self.fail("join() timed out")
@unittest.skipUnless(threading, 'Threading required for this test.')
+ @support.reap_threads
def test_listen_config_10_ok(self):
with support.captured_stdout() as output:
self.setup_via_listener(json.dumps(self.config10))
@@ -2885,6 +2898,7 @@ class ConfigDictTest(BaseTest):
], stream=output)
@unittest.skipUnless(threading, 'Threading required for this test.')
+ @support.reap_threads
def test_listen_config_1_ok(self):
with support.captured_stdout() as output:
self.setup_via_listener(textwrap.dedent(ConfigFileTest.config1))
@@ -2900,6 +2914,7 @@ class ConfigDictTest(BaseTest):
self.assert_log_lines([])
@unittest.skipUnless(threading, 'Threading required for this test.')
+ @support.reap_threads
def test_listen_verify(self):
def verify_fail(stuff):