From fab9550e8723adddc47e3fbd50e37da49a8a2afc Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 5 Nov 2017 10:32:10 -0500 Subject: [PATCH] testing: Connect to 127.0.0.1 instead of localhost The servers used in tests are only listening for ipv4, not ipv6 (to avoid spurious firewall prompts on macos). In what is apparently a recent macos change, connecting to `localhost` when the ipv6 port is unbound now incurs a 200ms delay, slowing a full test run down by a factor of 20. --- tornado/test/simple_httpclient_test.py | 2 +- tornado/test/web_test.py | 2 +- tornado/testing.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 309678efd..f8d1a0546 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -326,7 +326,7 @@ class SimpleHTTPClientTestMixin(object): self.assertNotIn("Content-Length", response.headers) def test_host_header(self): - host_re = re.compile(b"^localhost:[0-9]+$") + host_re = re.compile(b"^127.0.0.1:[0-9]+$") response = self.fetch("/host_echo") self.assertTrue(host_re.match(response.body)) diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 7c33fd901..7e3ac7c25 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -356,7 +356,7 @@ class AuthRedirectTest(WebTestCase): response = self.wait() self.assertEqual(response.code, 302) self.assertTrue(re.match( - 'http://example.com/login\?next=http%3A%2F%2Flocalhost%3A[0-9]+%2Fabsolute', + 'http://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2Fabsolute', response.headers['Location']), response.headers['Location']) diff --git a/tornado/testing.py b/tornado/testing.py index b79ba5928..86d4b5744 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -407,7 +407,7 @@ class AsyncHTTPTestCase(AsyncTestCase): def get_url(self, path): """Returns an absolute url for the given path on the test server.""" - return '%s://localhost:%s%s' % (self.get_protocol(), + return '%s://127.0.0.1:%s%s' % (self.get_protocol(), self.get_http_port(), path) def tearDown(self): -- 2.47.2