From: Ben Darnell Date: Sun, 5 Nov 2017 15:32:10 +0000 (-0500) Subject: testing: Connect to 127.0.0.1 instead of localhost X-Git-Tag: v4.5.3~1^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84bb2e285e15415bb86cbdf2326b19f0debb80fd;p=thirdparty%2Ftornado.git 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. --- diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index 02d57c5fb..451942d28 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -327,7 +327,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 d83446e42..013c2ac25 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 74d04b600..82a3b9373 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -423,7 +423,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):