summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2010-02-05 14:52:05 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2010-02-05 14:52:05 (GMT)
commit3dd734fe03dc15ac74f8e5a9403c7dcdf3321203 (patch)
tree7d17ce9e154c2b2f898fdf6e39d6fdbebd597999 /Lib/test
parent565d78586babda2b62cbe4f89c2dd3cace79c0fa (diff)
downloadcpython-3dd734fe03dc15ac74f8e5a9403c7dcdf3321203.zip
cpython-3dd734fe03dc15ac74f8e5a9403c7dcdf3321203.tar.gz
cpython-3dd734fe03dc15ac74f8e5a9403c7dcdf3321203.tar.bz2
Issue #7857: test_logging: listener test now uses find_unused_port().
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_logging.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 9b410e9..7453672 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -40,7 +40,8 @@ import string
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 @@ class ConfigDictTest(BaseTest):
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()
-
- 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()
+ try:
+ 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()
+ finally:
+ logging.config.stopListening()
+ t.join()
def test_listen_config_10_ok(self):
with captured_stdout() as output: