[Python-checkins] r60982 - python/trunk/Lib/test/test_logging.py

georg.brandl python-checkins at python.org
Sat Feb 23 16:06:25 CET 2008


Author: georg.brandl
Date: Sat Feb 23 16:06:25 2008
New Revision: 60982

Modified:
   python/trunk/Lib/test/test_logging.py
Log:
#2165: fix test_logging failure on some machines.


Modified: python/trunk/Lib/test/test_logging.py
==============================================================================
--- python/trunk/Lib/test/test_logging.py	(original)
+++ python/trunk/Lib/test/test_logging.py	Sat Feb 23 16:06:25 2008
@@ -2009,7 +2009,7 @@
                              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):
@@ -2018,11 +2018,11 @@
                                        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()
@@ -2107,28 +2107,18 @@
     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 = cStringIO.StringIO()
     sockLogger = logging.getLogger("logrecv")
     sockLogger.setLevel(logging.DEBUG)
@@ -2157,9 +2147,9 @@
 
     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())


More information about the Python-checkins mailing list