diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-21 22:39:46 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-21 22:39:46 (GMT) |
commit | f6fbf5607155b2dcd517059c8067305c4d015b00 (patch) | |
tree | 49d363b0218c7c9d8c36a64f029ca45ed49cf905 /Lib/test | |
parent | 13423c3726ac4aa42125ac49e6c5038a015fe3eb (diff) | |
download | cpython-f6fbf5607155b2dcd517059c8067305c4d015b00.zip cpython-f6fbf5607155b2dcd517059c8067305c4d015b00.tar.gz cpython-f6fbf5607155b2dcd517059c8067305c4d015b00.tar.bz2 |
Issue #18792: Use "127.0.0.1" or "::1" instead of "localhost" as much as possible, since "localhost" goes through a DNS lookup under recent Windows versions.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 10 | ||||
-rw-r--r-- | Lib/test/support/__init__.py | 6 | ||||
-rw-r--r-- | Lib/test/test_asyncore.py | 5 | ||||
-rw-r--r-- | Lib/test/test_ftplib.py | 8 | ||||
-rw-r--r-- | Lib/test/test_timeout.py | 2 |
5 files changed, 17 insertions, 14 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index f9be810..d1c7f0b 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1999,7 +1999,7 @@ class _TestRemoteManager(BaseTestCase): authkey = os.urandom(32) manager = QueueManager( - address=('localhost', 0), authkey=authkey, serializer=SERIALIZER + address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER ) manager.start() @@ -2037,7 +2037,7 @@ class _TestManagerRestart(BaseTestCase): def test_rapid_restart(self): authkey = os.urandom(32) manager = QueueManager( - address=('localhost', 0), authkey=authkey, serializer=SERIALIZER) + address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER) srvr = manager.get_server() addr = srvr.address # Close the connection.Listener socket which gets opened as a part @@ -2509,7 +2509,7 @@ class _TestPicklingConnections(BaseTestCase): l.close() l = socket.socket() - l.bind(('localhost', 0)) + l.bind((test.support.HOST, 0)) l.listen(1) conn.send(l.getsockname()) new_conn, addr = l.accept() @@ -3151,9 +3151,9 @@ class TestWait(unittest.TestCase): def test_wait_socket(self, slow=False): from multiprocessing.connection import wait l = socket.socket() - l.bind(('', 0)) + l.bind((test.support.HOST, 0)) l.listen(4) - addr = ('localhost', l.getsockname()[1]) + addr = l.getsockname() readers = [] procs = [] dic = {} diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index befbe8b..02ea298 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -480,7 +480,11 @@ def requires_mac_ver(*min_version): return decorator -HOST = 'localhost' +# Don't use "localhost", since resolving it uses the DNS under recent +# Windows versions (see issue #18792). +HOST = "127.0.0.1" +HOSTv6 = "::1" + def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM): """Returns an unused port that should be suitable for binding. This is diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py index c02a976..87655f4 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -10,7 +10,7 @@ import errno import struct from test import support -from test.support import TESTFN, run_unittest, unlink +from test.support import TESTFN, run_unittest, unlink, HOST, HOSTv6 from io import BytesIO from io import StringIO @@ -19,7 +19,6 @@ try: except ImportError: threading = None -HOST = support.HOST TIMEOUT = 3 HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX') @@ -816,7 +815,7 @@ class TestAPI_UseIPv4Sockets(BaseTestAPI): @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 support required') class TestAPI_UseIPv6Sockets(BaseTestAPI): family = socket.AF_INET6 - addr = ('::1', 0) + addr = (HOSTv6, 0) @unittest.skipUnless(HAS_UNIX_SOCKETS, 'Unix sockets required') class TestAPI_UseUnixSockets(BaseTestAPI): diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 25e34be..08d99d8 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -18,7 +18,7 @@ except ImportError: from unittest import TestCase from test import support -from test.support import HOST +from test.support import HOST, HOSTv6 threading = support.import_module('threading') TIMEOUT = 3 @@ -767,7 +767,7 @@ class TestFTPClass(TestCase): class TestIPv6Environment(TestCase): def setUp(self): - self.server = DummyFTPServer(('::1', 0), af=socket.AF_INET6) + self.server = DummyFTPServer((HOSTv6, 0), af=socket.AF_INET6) self.server.start() self.client = ftplib.FTP(timeout=TIMEOUT) self.client.connect(self.server.host, self.server.port) @@ -950,7 +950,7 @@ class TestTimeouts(TestCase): self.assertTrue(socket.getdefaulttimeout() is None) socket.setdefaulttimeout(30) try: - ftp = ftplib.FTP("localhost") + ftp = ftplib.FTP(HOST) finally: socket.setdefaulttimeout(None) self.assertEqual(ftp.sock.gettimeout(), 30) @@ -962,7 +962,7 @@ class TestTimeouts(TestCase): self.assertTrue(socket.getdefaulttimeout() is None) socket.setdefaulttimeout(30) try: - ftp = ftplib.FTP("localhost", timeout=None) + ftp = ftplib.FTP(HOST, timeout=None) finally: socket.setdefaulttimeout(None) self.assertTrue(ftp.sock.gettimeout() is None) diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py index fe7b264..703c43a 100644 --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -110,7 +110,7 @@ class TimeoutTestCase(unittest.TestCase): # solution. fuzz = 2.0 - localhost = '127.0.0.1' + localhost = support.HOST def setUp(self): raise NotImplementedError() |