Skip to content

[3.6] bpo-30131: test_logging now joins queue threads (#1298) #1317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3163,6 +3163,7 @@ def setup_and_log(log_queue, ident):
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()
Expand All @@ -3172,10 +3173,13 @@ def test_handle_called_with_queue_queue(self, mock_handle):

@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')

Expand All @@ -3188,6 +3192,7 @@ def get_all_from_queue(log_queue):
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
Expand All @@ -3200,6 +3205,9 @@ def test_no_messages_in_queue_after_stop(self):
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' % (
Expand Down