Skip to content
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

bpo-30830: test_logging uses threading_setup/cleanup #3137

Merged
merged 3 commits into from
Aug 18, 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
23 changes: 14 additions & 9 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class BaseTest(unittest.TestCase):
def setUp(self):
"""Setup the default logging stream to an internal StringIO instance,
so that we can examine log output as we want."""
self._threading_key = support.threading_setup()

logger_dict = logging.getLogger().manager.loggerDict
logging._acquireLock()
try:
Expand Down Expand Up @@ -147,6 +149,9 @@ def tearDown(self):
finally:
logging._releaseLock()

self.doCleanups()
support.threading_cleanup(*self._threading_key)

def assert_log_lines(self, expected_values, stream=None, pat=None):
"""Match the collected log lines against the regular expression
self.expected_log_pat, and compare the extracted group values to
Expand Down Expand Up @@ -621,7 +626,6 @@ def test_path_objects(self):

@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):
Expand Down Expand Up @@ -986,7 +990,6 @@ class TestUnixDatagramServer(TestUDPServer):
class SMTPHandlerTest(BaseTest):
TIMEOUT = 8.0

@support.reap_threads
def test_basic(self):
sockmap = {}
server = TestSMTPServer((support.HOST, 0), self.process_message, 0.001,
Expand Down Expand Up @@ -1466,6 +1469,7 @@ def test_logger_disabling(self):
self.assertFalse(logger.disabled)


@unittest.skipIf(True, "FIXME: bpo-30830")
@unittest.skipUnless(threading, 'Threading required for this test.')
class SocketHandlerTest(BaseTest):

Expand Down Expand Up @@ -1565,6 +1569,7 @@ def _get_temp_domain_socket():
os.remove(fn)
return fn

@unittest.skipIf(True, "FIXME: bpo-30830")
@unittest.skipUnless(hasattr(socket, "AF_UNIX"), "Unix sockets required")
@unittest.skipUnless(threading, 'Threading required for this test.')
class UnixSocketHandlerTest(SocketHandlerTest):
Expand All @@ -1583,6 +1588,7 @@ def tearDown(self):
SocketHandlerTest.tearDown(self)
support.unlink(self.address)

@unittest.skipIf(True, "FIXME: bpo-30830")
@unittest.skipUnless(threading, 'Threading required for this test.')
class DatagramHandlerTest(BaseTest):

Expand Down Expand Up @@ -1649,6 +1655,7 @@ def test_output(self):
self.handled.wait()
self.assertEqual(self.log_output, "spam\neggs\n")

@unittest.skipIf(True, "FIXME: bpo-30830")
@unittest.skipUnless(hasattr(socket, "AF_UNIX"), "Unix sockets required")
@unittest.skipUnless(threading, 'Threading required for this test.')
class UnixDatagramHandlerTest(DatagramHandlerTest):
Expand Down Expand Up @@ -1736,6 +1743,7 @@ def test_output(self):
self.handled.wait()
self.assertEqual(self.log_output, b'<11>h\xc3\xa4m-sp\xc3\xa4m')

@unittest.skipIf(True, "FIXME: bpo-30830")
@unittest.skipUnless(hasattr(socket, "AF_UNIX"), "Unix sockets required")
@unittest.skipUnless(threading, 'Threading required for this test.')
class UnixSysLogHandlerTest(SysLogHandlerTest):
Expand All @@ -1754,6 +1762,7 @@ def tearDown(self):
SysLogHandlerTest.tearDown(self)
support.unlink(self.address)

@unittest.skipIf(True, "FIXME: bpo-30830")
@unittest.skipUnless(support.IPV6_ENABLED,
'IPv6 support required for this test.')
@unittest.skipUnless(threading, 'Threading required for this test.')
Expand Down Expand Up @@ -1795,7 +1804,6 @@ def handle_request(self, request):
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")
Expand Down Expand Up @@ -2879,6 +2887,9 @@ def test_config14_ok(self):
logging.warning('Exclamation')
self.assertTrue(output.getvalue().endswith('Exclamation!\n'))

# listen() uses ConfigSocketReceiver which is based
# on socketserver.ThreadingTCPServer
@unittest.skipIf(True, "FIXME: bpo-30830")
@unittest.skipUnless(threading, 'listen() needs threading to work')
def setup_via_listener(self, text, verify=None):
text = text.encode("utf-8")
Expand Down Expand Up @@ -2911,7 +2922,6 @@ def setup_via_listener(self, text, verify=None):
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))
Expand All @@ -2932,7 +2942,6 @@ def test_listen_config_10_ok(self):
], 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))
Expand All @@ -2948,7 +2957,6 @@ def test_listen_config_1_ok(self):
self.assert_log_lines([])

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

def verify_fail(stuff):
Expand Down Expand Up @@ -3232,7 +3240,6 @@ 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 @@ -3242,7 +3249,6 @@ 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()
Expand All @@ -3261,7 +3267,6 @@ 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 Down