From 43616131dc5e27bb49b849ed597a98772c5bbb95 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 7 Jul 2011 22:21:59 -0400 Subject: CHOP-661: Fix HTTPServer usage to turn off allow_reuse_address. Turns out that BaseHTTPServer.HTTPServer turns on that flag by default, which causes freeport() to fail (on Windows only?), happily instantiating multiple servers on the same port. Change known instances, fix freeport() docstring to highlight the issue. Add freeport() unit tests to verify expected behavior. --- indra/llmessage/tests/test_llsdmessage_peer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'indra/llmessage/tests/test_llsdmessage_peer.py') diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index 9886d49ccc..22edd9dad8 100644 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -124,14 +124,19 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler): # Suppress error output as well pass +class Server(HTTPServer): + # This pernicious flag is on by default in HTTPServer. But proper + # operation of freeport() absolutely depends on it being off. + allow_reuse_address = False + if __name__ == "__main__": - # Instantiate an HTTPServer(TestHTTPRequestHandler) on the first free port + # Instantiate a Server(TestHTTPRequestHandler) on the first free port # in the specified port range. Doing this inline is better than in a # daemon thread: if it blows up here, we'll get a traceback. If it blew up # in some other thread, the traceback would get eaten and we'd run the # subject test program anyway. httpd, port = freeport(xrange(8000, 8020), - lambda port: HTTPServer(('127.0.0.1', port), TestHTTPRequestHandler)) + lambda port: Server(('127.0.0.1', port), TestHTTPRequestHandler)) # Pass the selected port number to the subject test program via the # environment. We don't want to impose requirements on the test program's # command-line parsing -- and anyway, for C++ integration tests, that's -- cgit v1.2.3