[Python-checkins] r77985 - python/trunk/Lib/test/test_logging.py
vinay.sajip
python-checkins at python.org
Fri Feb 5 15:52:05 CET 2010
Author: vinay.sajip
Date: Fri Feb 5 15:52:05 2010
New Revision: 77985
Log:
Issue #7857: test_logging: listener test now uses find_unused_port().
Modified:
python/trunk/Lib/test/test_logging.py
Modified: python/trunk/Lib/test/test_logging.py
==============================================================================
--- python/trunk/Lib/test/test_logging.py (original)
+++ python/trunk/Lib/test/test_logging.py Fri Feb 5 15:52:05 2010
@@ -40,7 +40,8 @@
import struct
import sys
import tempfile
-from test.test_support import captured_stdout, run_with_locale, run_unittest
+from test.test_support import captured_stdout, run_with_locale, run_unittest,\
+ find_unused_port
import textwrap
import threading
import time
@@ -1573,24 +1574,25 @@
self.test_config1_ok(self.config11)
def setup_via_listener(self, text):
- PORT = 9030
- t = logging.config.listen(PORT)
+ port = find_unused_port()
+ t = logging.config.listen(port)
t.start()
+ try:
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect(('localhost', port))
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect(('localhost', PORT))
-
- slen = struct.pack('>L', len(text))
- s = slen + text
- sentsofar = 0
- left = len(s)
- while left > 0:
- sent = sock.send(s[sentsofar:])
- sentsofar += sent
- left -= sent
- sock.close()
- logging.config.stopListening()
- t.join()
+ slen = struct.pack('>L', len(text))
+ s = slen + text
+ sentsofar = 0
+ left = len(s)
+ while left > 0:
+ sent = sock.send(s[sentsofar:])
+ sentsofar += sent
+ left -= sent
+ sock.close()
+ finally:
+ logging.config.stopListening()
+ t.join()
def test_listen_config_10_ok(self):
with captured_stdout() as output:
More information about the Python-checkins
mailing list