From: Ben Darnell Date: Sun, 5 Jun 2011 19:13:08 +0000 (-0700) Subject: Only listen on localhost so unittests don't cause firewall warnings X-Git-Tag: v2.0.0~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6268052ca9815d0f7b99b59cc0394affe8612949;p=thirdparty%2Ftornado.git Only listen on localhost so unittests don't cause firewall warnings --- diff --git a/tornado/httpserver.py b/tornado/httpserver.py index f5ab0e6c8..5c575c8be 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -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. diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index a3c499806..4a7c1e9fc 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -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 diff --git a/tornado/testing.py b/tornado/testing.py index fa9113964..2e58b6c8a 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -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