diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-04-26 13:56:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-26 13:56:25 (GMT) |
commit | 8ca2f2faefa8dba323a2e4c4b86efb633d7a53cf (patch) | |
tree | 69eac526d6e7846dc365809d8ee8225817935ce6 | |
parent | 6e676954de7c4f3f06dd5b56842c9a2c931a1cab (diff) | |
download | cpython-8ca2f2faefa8dba323a2e4c4b86efb633d7a53cf.zip cpython-8ca2f2faefa8dba323a2e4c4b86efb633d7a53cf.tar.gz cpython-8ca2f2faefa8dba323a2e4c4b86efb633d7a53cf.tar.bz2 |
bpo-30131: test_logging now joins queue threads (#1298)
QueueListenerTest of test_logging now closes the multiprocessing
Queue and joins its thread to prevent leaking dangling threads to
following tests.
Add also @support.reap_threads to detect earlier if a test leaks
threads (and try to "cleanup" these threads).
-rw-r--r-- | Lib/test/test_logging.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index ca7a774..85c8225 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3184,6 +3184,7 @@ if hasattr(logging.handlers, 'QueueListener'): handler.close() @patch.object(logging.handlers.QueueListener, 'handle') + @support.reap_threads def test_handle_called_with_queue_queue(self, mock_handle): for i in range(self.repeat): log_queue = queue.Queue() @@ -3193,10 +3194,13 @@ if hasattr(logging.handlers, 'QueueListener'): @support.requires_multiprocessing_queue @patch.object(logging.handlers.QueueListener, 'handle') + @support.reap_threads def test_handle_called_with_mp_queue(self, mock_handle): for i in range(self.repeat): log_queue = multiprocessing.Queue() self.setup_and_log(log_queue, '%s_%s' % (self.id(), i)) + log_queue.close() + log_queue.join_thread() self.assertEqual(mock_handle.call_count, 5 * self.repeat, 'correct number of handled log messages') @@ -3209,6 +3213,7 @@ if hasattr(logging.handlers, 'QueueListener'): return [] @support.requires_multiprocessing_queue + @support.reap_threads def test_no_messages_in_queue_after_stop(self): """ Five messages are logged then the QueueListener is stopped. This @@ -3221,6 +3226,9 @@ if hasattr(logging.handlers, 'QueueListener'): self.setup_and_log(queue, '%s_%s' %(self.id(), i)) # time.sleep(1) items = list(self.get_all_from_queue(queue)) + queue.close() + queue.join_thread() + expected = [[], [logging.handlers.QueueListener._sentinel]] self.assertIn(items, expected, 'Found unexpected messages in queue: %s' % ( |