]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Replace most testing uses of 'localhost' with '127.0.0.1'.
authorBen Darnell <ben@bendarnell.com>
Sun, 25 Jan 2015 00:50:04 +0000 (19:50 -0500)
committerBen Darnell <ben@bendarnell.com>
Sun, 25 Jan 2015 00:50:04 +0000 (19:50 -0500)
This may work around a suspected ipv6-related issue on travis.

tornado/test/httpclient_test.py
tornado/test/httpserver_test.py
tornado/test/iostream_test.py
tornado/test/simple_httpclient_test.py
tornado/test/twisted_test.py
tornado/test/web_test.py
tornado/test/websocket_test.py

index b155c6eebf688ad5178337bebc37905816dcde45..875864ac69ff66ab851a8b95819ba6f62e1fc607 100644 (file)
@@ -548,7 +548,7 @@ class SyncHTTPClientTest(unittest.TestCase):
         self.server_ioloop.close(all_fds=True)
 
     def get_url(self, path):
-        return 'http://localhost:%d%s' % (self.port, path)
+        return 'http://127.0.0.1:%d%s' % (self.port, path)
 
     def test_sync_client(self):
         response = self.http_client.fetch(self.get_url('/'))
index 1a7540c94be727275c9ced1bec086fa95f8318b3..64ef96d459406d7224bbe1e968da62824ffc6291 100644 (file)
@@ -244,7 +244,7 @@ class HTTPConnectionTest(AsyncHTTPTestCase):
         # When given Expect: 100-continue, we get a 100 response after the
         # headers, and then the real response after the body.
         stream = IOStream(socket.socket(), io_loop=self.io_loop)
-        stream.connect(("localhost", self.get_http_port()), callback=self.stop)
+        stream.connect(("127.0.0.1", self.get_http_port()), callback=self.stop)
         self.wait()
         stream.write(b"\r\n".join([b"POST /hello HTTP/1.1",
                                    b"Content-Length: 1024",
@@ -381,7 +381,7 @@ class HTTPServerRawTest(AsyncHTTPTestCase):
     def setUp(self):
         super(HTTPServerRawTest, self).setUp()
         self.stream = IOStream(socket.socket())
-        self.stream.connect(('localhost', self.get_http_port()), self.stop)
+        self.stream.connect(('127.0.0.1', self.get_http_port()), self.stop)
         self.wait()
 
     def tearDown(self):
@@ -630,7 +630,7 @@ class KeepAliveTest(AsyncHTTPTestCase):
     # The next few methods are a crude manual http client
     def connect(self):
         self.stream = IOStream(socket.socket(), io_loop=self.io_loop)
-        self.stream.connect(('localhost', self.get_http_port()), self.stop)
+        self.stream.connect(('127.0.0.1', self.get_http_port()), self.stop)
         self.wait()
 
     def read_headers(self):
@@ -907,7 +907,7 @@ class IdleTimeoutTest(AsyncHTTPTestCase):
 
     def connect(self):
         stream = IOStream(socket.socket())
-        stream.connect(('localhost', self.get_http_port()), self.stop)
+        stream.connect(('127.0.0.1', self.get_http_port()), self.stop)
         self.wait()
         self.streams.append(stream)
         return stream
index f8f30b498855521c02f73cf4729212c0413f955f..ca35de69bbae0b48467642c4b157e17f3878cab1 100644 (file)
@@ -51,7 +51,7 @@ class TestIOStreamWebMixin(object):
 
     def test_read_until_close(self):
         stream = self._make_client_iostream()
-        stream.connect(('localhost', self.get_http_port()), callback=self.stop)
+        stream.connect(('127.0.0.1', self.get_http_port()), callback=self.stop)
         self.wait()
         stream.write(b"GET / HTTP/1.0\r\n\r\n")
 
@@ -62,7 +62,7 @@ class TestIOStreamWebMixin(object):
 
     def test_read_zero_bytes(self):
         self.stream = self._make_client_iostream()
-        self.stream.connect(("localhost", self.get_http_port()),
+        self.stream.connect(("127.0.0.1", self.get_http_port()),
                             callback=self.stop)
         self.wait()
         self.stream.write(b"GET / HTTP/1.0\r\n\r\n")
@@ -91,7 +91,7 @@ class TestIOStreamWebMixin(object):
         def connected_callback():
             connected[0] = True
             self.stop()
-        stream.connect(("localhost", self.get_http_port()),
+        stream.connect(("127.0.0.1", self.get_http_port()),
                        callback=connected_callback)
         # unlike the previous tests, try to write before the connection
         # is complete.
@@ -121,7 +121,7 @@ class TestIOStreamWebMixin(object):
         """Basic test of IOStream's ability to return Futures."""
         stream = self._make_client_iostream()
         connect_result = yield stream.connect(
-            ("localhost", self.get_http_port()))
+            ("127.0.0.1", self.get_http_port()))
         self.assertIs(connect_result, stream)
         yield stream.write(b"GET / HTTP/1.0\r\n\r\n")
         first_line = yield stream.read_until(b"\r\n")
@@ -137,7 +137,7 @@ class TestIOStreamWebMixin(object):
     @gen_test
     def test_future_close_while_reading(self):
         stream = self._make_client_iostream()
-        yield stream.connect(("localhost", self.get_http_port()))
+        yield stream.connect(("127.0.0.1", self.get_http_port()))
         yield stream.write(b"GET / HTTP/1.0\r\n\r\n")
         with self.assertRaises(StreamClosedError):
             yield stream.read_bytes(1024 * 1024)
@@ -147,7 +147,7 @@ class TestIOStreamWebMixin(object):
     def test_future_read_until_close(self):
         # Ensure that the data comes through before the StreamClosedError.
         stream = self._make_client_iostream()
-        yield stream.connect(("localhost", self.get_http_port()))
+        yield stream.connect(("127.0.0.1", self.get_http_port()))
         yield stream.write(b"GET / HTTP/1.0\r\nConnection: close\r\n\r\n")
         yield stream.read_until(b"\r\n\r\n")
         body = yield stream.read_until_close()
index a059bc933f50eabf72dfac772c1bbc081da21f4b..bb870db3b0308d109687ff78241b0c3edb7b67bb 100644 (file)
@@ -325,7 +325,7 @@ class SimpleHTTPClientTestMixin(object):
         cleanup_func, port = refusing_port()
         self.addCleanup(cleanup_func)
         with ExpectLog(gen_log, ".*", required=False):
-            self.http_client.fetch("http://localhost:%d/" % port, self.stop)
+            self.http_client.fetch("http://127.0.0.1:%d/" % port, self.stop)
             response = self.wait()
         self.assertEqual(599, response.code)
 
index a1a2e24c41320037e670d9bf778dcdd2270d8940..9af06a7ac1e6f4a0c4911cff0026fb4326c394b3 100644 (file)
@@ -453,32 +453,32 @@ class CompatibilityTests(unittest.TestCase):
     def testTwistedServerTornadoClientIOLoop(self):
         self.start_twisted_server()
         response = self.tornado_fetch(
-            'http://localhost:%d' % self.twisted_port, self.run_ioloop)
+            'http://127.0.0.1:%d' % self.twisted_port, self.run_ioloop)
         self.assertEqual(response.body, 'Hello from twisted!')
 
     def testTwistedServerTornadoClientReactor(self):
         self.start_twisted_server()
         response = self.tornado_fetch(
-            'http://localhost:%d' % self.twisted_port, self.run_reactor)
+            'http://127.0.0.1:%d' % self.twisted_port, self.run_reactor)
         self.assertEqual(response.body, 'Hello from twisted!')
 
     def testTornadoServerTwistedClientIOLoop(self):
         self.start_tornado_server()
         response = self.twisted_fetch(
-            'http://localhost:%d' % self.tornado_port, self.run_ioloop)
+            'http://127.0.0.1:%d' % self.tornado_port, self.run_ioloop)
         self.assertEqual(response, 'Hello from tornado!')
 
     def testTornadoServerTwistedClientReactor(self):
         self.start_tornado_server()
         response = self.twisted_fetch(
-            'http://localhost:%d' % self.tornado_port, self.run_reactor)
+            'http://127.0.0.1:%d' % self.tornado_port, self.run_reactor)
         self.assertEqual(response, 'Hello from tornado!')
 
     @skipIfNoSingleDispatch
     def testTornadoServerTwistedCoroutineClientIOLoop(self):
         self.start_tornado_server()
         response = self.twisted_coroutine_fetch(
-            'http://localhost:%d' % self.tornado_port, self.run_ioloop)
+            'http://127.0.0.1:%d' % self.tornado_port, self.run_ioloop)
         self.assertEqual(response, 'Hello from tornado!')
 
 
index 55c9c9e8c99075cec964e8173e461cfb3c43d8aa..77ad388812de95585673b261e6b608b8f41a25d3 100644 (file)
@@ -305,7 +305,7 @@ class ConnectionCloseTest(WebTestCase):
 
     def test_connection_close(self):
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
-        s.connect(("localhost", self.get_http_port()))
+        s.connect(("127.0.0.1", self.get_http_port()))
         self.stream = IOStream(s, io_loop=self.io_loop)
         self.stream.write(b"GET / HTTP/1.0\r\n\r\n")
         self.wait()
@@ -1907,7 +1907,7 @@ class StreamingRequestBodyTest(WebTestCase):
     def connect(self, url, connection_close):
         # Use a raw connection so we can control the sending of data.
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
-        s.connect(("localhost", self.get_http_port()))
+        s.connect(("127.0.0.1", self.get_http_port()))
         stream = IOStream(s, io_loop=self.io_loop)
         stream.write(b"GET " + url + b" HTTP/1.1\r\n")
         if connection_close:
index 443ad8758a853c317eed4802a763e0ae83599ea2..7e93d17141a886a9cb06a5f840a11f7e723b9dae 100644 (file)
@@ -92,7 +92,7 @@ class WebSocketBaseTestCase(AsyncHTTPTestCase):
     @gen.coroutine
     def ws_connect(self, path, compression_options=None):
         ws = yield websocket_connect(
-            'ws://localhost:%d%s' % (self.get_http_port(), path),
+            'ws://127.0.0.1:%d%s' % (self.get_http_port(), path),
             compression_options=compression_options)
         raise gen.Return(ws)
 
@@ -136,7 +136,7 @@ class WebSocketTest(WebSocketBaseTestCase):
 
     def test_websocket_callbacks(self):
         websocket_connect(
-            'ws://localhost:%d/echo' % self.get_http_port(),
+            'ws://127.0.0.1:%d/echo' % self.get_http_port(),
             io_loop=self.io_loop, callback=self.stop)
         ws = self.wait().result()
         ws.write_message('hello')
@@ -190,14 +190,14 @@ class WebSocketTest(WebSocketBaseTestCase):
         with self.assertRaises(IOError):
             with ExpectLog(gen_log, ".*"):
                 yield websocket_connect(
-                    'ws://localhost:%d/' % port,
+                    'ws://127.0.0.1:%d/' % port,
                     io_loop=self.io_loop,
                     connect_timeout=3600)
 
     @gen_test
     def test_websocket_close_buffered_data(self):
         ws = yield websocket_connect(
-            'ws://localhost:%d/echo' % self.get_http_port())
+            'ws://127.0.0.1:%d/echo' % self.get_http_port())
         ws.write_message('hello')
         ws.write_message('world')
         # Close the underlying stream.
@@ -208,7 +208,7 @@ class WebSocketTest(WebSocketBaseTestCase):
     def test_websocket_headers(self):
         # Ensure that arbitrary headers can be passed through websocket_connect.
         ws = yield websocket_connect(
-            HTTPRequest('ws://localhost:%d/header' % self.get_http_port(),
+            HTTPRequest('ws://127.0.0.1:%d/header' % self.get_http_port(),
                         headers={'X-Test': 'hello'}))
         response = yield ws.read_message()
         self.assertEqual(response, 'hello')
@@ -246,8 +246,8 @@ class WebSocketTest(WebSocketBaseTestCase):
     def test_check_origin_valid_no_path(self):
         port = self.get_http_port()
 
-        url = 'ws://localhost:%d/echo' % port
-        headers = {'Origin': 'http://localhost:%d' % port}
+        url = 'ws://127.0.0.1:%d/echo' % port
+        headers = {'Origin': 'http://127.0.0.1:%d' % port}
 
         ws = yield websocket_connect(HTTPRequest(url, headers=headers),
             io_loop=self.io_loop)
@@ -260,8 +260,8 @@ class WebSocketTest(WebSocketBaseTestCase):
     def test_check_origin_valid_with_path(self):
         port = self.get_http_port()
 
-        url = 'ws://localhost:%d/echo' % port
-        headers = {'Origin': 'http://localhost:%d/something' % port}
+        url = 'ws://127.0.0.1:%d/echo' % port
+        headers = {'Origin': 'http://127.0.0.1:%d/something' % port}
 
         ws = yield websocket_connect(HTTPRequest(url, headers=headers),
             io_loop=self.io_loop)
@@ -274,8 +274,8 @@ class WebSocketTest(WebSocketBaseTestCase):
     def test_check_origin_invalid_partial_url(self):
         port = self.get_http_port()
 
-        url = 'ws://localhost:%d/echo' % port
-        headers = {'Origin': 'localhost:%d' % port}
+        url = 'ws://127.0.0.1:%d/echo' % port
+        headers = {'Origin': '127.0.0.1:%d' % port}
 
         with self.assertRaises(HTTPError) as cm:
             yield websocket_connect(HTTPRequest(url, headers=headers),
@@ -286,8 +286,8 @@ class WebSocketTest(WebSocketBaseTestCase):
     def test_check_origin_invalid(self):
         port = self.get_http_port()
 
-        url = 'ws://localhost:%d/echo' % port
-        # Host is localhost, which should not be accessible from some other
+        url = 'ws://127.0.0.1:%d/echo' % port
+        # Host is 127.0.0.1, which should not be accessible from some other
         # domain
         headers = {'Origin': 'http://somewhereelse.com'}