]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Only listen on localhost so unittests don't cause firewall warnings
authorBen Darnell <ben@bendarnell.com>
Sun, 5 Jun 2011 19:13:08 +0000 (12:13 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 5 Jun 2011 19:13:08 +0000 (12:13 -0700)
tornado/httpserver.py
tornado/test/httpclient_test.py
tornado/testing.py

index f5ab0e6c848bb4a9049b872e023599381efe68b0..5c575c8beb6849c310b959eea3ccfc9829694818 100644 (file)
@@ -175,7 +175,6 @@ class HTTPServer(object):
         """
         if address == "":
             address = None
-        success = 0
         for res in socket.getaddrinfo(address, port, family, socket.SOCK_STREAM,
                                       0, socket.AI_PASSIVE | socket.AI_ADDRCONFIG):
             af, socktype, proto, canonname, sockaddr = res
@@ -199,7 +198,9 @@ class HTTPServer(object):
             sock.bind(sockaddr)
             sock.listen(128)
             self._sockets[sock.fileno()] = sock
-            success += 1
+            if self._started:
+                self.io_loop.add_handler(sock.fileno(), self._handle_events,
+                                         ioloop.IOLoop.READ)
 
     def start(self, num_processes=1):
         """Starts this server in the IOLoop.
index a3c49980620042ac34bdbfa180efd918c45f8731..4a7c1e9fc38126ed100d4f82f292bb11f3e0089d 100644 (file)
@@ -138,7 +138,7 @@ class HTTPClientCommonTestCase(AsyncHTTPTestCase, LogTrapTestCase):
 
         with closing(socket.socket()) as sock:
             sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-            sock.bind(('', port))
+            sock.bind(('127.0.0.1', port))
             sock.listen(1)
             self.http_client.fetch("http://localhost:%d/" % port,
                                    self.stop,
@@ -204,6 +204,7 @@ class HTTPClientCommonTestCase(AsyncHTTPTestCase, LogTrapTestCase):
         self.assertEqual(response.body, byte_body)
 
     def test_ipv6(self):
+        self.http_server.bind(self.get_http_port(), address='::1')
         url = self.get_url("/hello").replace("localhost", "[::1]")
 
         # ipv6 is currently disabled by default and must be explicitly requested
index fa91139643c6abbc63ab435df90540ed6270ba42..2e58b6c8aa6d097d8f5320341715c4b63445fa14 100644 (file)
@@ -220,7 +220,7 @@ class AsyncHTTPTestCase(AsyncTestCase):
         self._app = self.get_app()
         self.http_server = HTTPServer(self._app, io_loop=self.io_loop,
                                       **self.get_httpserver_options())
-        self.http_server.listen(self.get_http_port())
+        self.http_server.listen(self.get_http_port(), address="127.0.0.1")
 
     def get_app(self):
         """Should be overridden by subclasses to return a