summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_logging.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r--Lib/test/test_logging.py39
1 files changed, 14 insertions, 25 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index a31ad37..66aa9fa 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -1828,8 +1828,7 @@ Test Main
>>> import logging, logging.handlers, logging.config
>>> from test import test_logging
-XXX: The test is unstable!
-#>>> test_logging.test_main_inner()
+>>> test_logging.test_main_inner()
ERR -> CRITICAL: Message 0 (via logrecv.tcp.ERR)
ERR -> ERROR: Message 1 (via logrecv.tcp.ERR)
INF -> CRITICAL: Message 2 (via logrecv.tcp.INF)
@@ -2010,7 +2009,7 @@ class LogRecordSocketReceiver(ThreadingTCPServer):
port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
handler=LogRecordStreamHandler):
ThreadingTCPServer.__init__(self, (host, port), handler)
- self.abort = 0
+ self.abort = False
self.timeout = 1
def serve_until_stopped(self):
@@ -2019,11 +2018,11 @@ class LogRecordSocketReceiver(ThreadingTCPServer):
self.timeout)
if rd:
self.handle_request()
+ socketDataProcessed.set()
# close the listen socket
self.server_close()
def process_request(self, request, client_address):
- #import threading
t = threading.Thread(target = self.finish_request,
args = (request, client_address))
t.start()
@@ -2108,28 +2107,18 @@ def test_main_inner():
rootLogger = logging.getLogger("")
rootLogger.setLevel(logging.DEBUG)
- # Find an unused port number
- port = logging.handlers.DEFAULT_TCP_LOGGING_PORT
- while port < logging.handlers.DEFAULT_TCP_LOGGING_PORT+100:
- try:
- tcpserver = LogRecordSocketReceiver(port=port)
- except socket.error:
- port += 1
- else:
- break
- else:
- raise ImportError("Could not find unused port")
-
-
- #Set up a handler such that all events are sent via a socket to the log
- #receiver (logrecv).
- #The handler will only be added to the rootLogger for some of the tests
+ tcpserver = LogRecordSocketReceiver(port=0)
+ port = tcpserver.socket.getsockname()[1]
+
+ # Set up a handler such that all events are sent via a socket to the log
+ # receiver (logrecv).
+ # The handler will only be added to the rootLogger for some of the tests
shdlr = logging.handlers.SocketHandler('localhost', port)
rootLogger.addHandler(shdlr)
- #Configure the logger for logrecv so events do not propagate beyond it.
- #The sockLogger output is buffered in memory until the end of the test,
- #and printed at the end.
+ # Configure the logger for logrecv so events do not propagate beyond it.
+ # The sockLogger output is buffered in memory until the end of the test,
+ # and printed at the end.
sockOut = io.StringIO()
sockLogger = logging.getLogger("logrecv")
sockLogger.setLevel(logging.DEBUG)
@@ -2158,9 +2147,9 @@ def test_main_inner():
finally:
#wait for TCP receiver to terminate
-# socketDataProcessed.wait()
+ socketDataProcessed.wait()
# ensure the server dies
- tcpserver.abort = 1
+ tcpserver.abort = True
for thread in threads:
thread.join(2.0)
print(sockOut.getvalue())