diff options
Diffstat (limited to 'Lib/test/test_xmlrpc.py')
-rw-r--r-- | Lib/test/test_xmlrpc.py | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index e285809958..7c68e4cc6e 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -232,7 +232,7 @@ class BinaryTestCase(unittest.TestCase): self.assertEqual(str(t2), str(d, "latin-1")) -PORT = None +ADDR = PORT = URL = None # The evt is set twice. First when the server is ready to serve. # Second when the server has been shutdown. The user must clear @@ -258,12 +258,17 @@ def http_server(evt, numrequests): s.setblocking(True) return s, port + serv = MyXMLRPCServer(("localhost", 0), + logRequests=False, bind_and_activate=False) try: - serv = MyXMLRPCServer(("localhost", 0), - logRequests=False, bind_and_activate=False) serv.server_bind() - global PORT - PORT = serv.socket.getsockname()[1] + global ADDR, PORT, URL + ADDR, PORT = serv.socket.getsockname() + #connect to IP address directly. This avoids socket.create_connection() + #trying to connect to to "localhost" using all address families, which + #causes slowdown e.g. on vista which supports AF_INET6. The server listens + #on AF_INET only. + URL = "http://%s:%d"%(ADDR, PORT) serv.server_activate() serv.register_introspection_functions() serv.register_multicall_functions() @@ -331,7 +336,7 @@ class SimpleServerTestCase(unittest.TestCase): def test_simple1(self): try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) except (xmlrpclib.ProtocolError, socket.error) as e: # ignore failures due to non-blocking socket 'unavailable' errors @@ -343,7 +348,7 @@ class SimpleServerTestCase(unittest.TestCase): def XXXtest_404(self): # send POST with http.client, it should return 404 header and # 'Not Found' message. - conn = http.client.HTTPConnection('localhost', PORT) + conn = httplib.client.HTTPConnection(ADDR, PORT) conn.request('POST', '/this-is-not-valid') response = conn.getresponse() conn.close() @@ -356,7 +361,7 @@ class SimpleServerTestCase(unittest.TestCase): 'system.listMethods', 'system.methodHelp', 'system.methodSignature', 'system.multicall']) try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) meth = p.system.listMethods() self.assertEqual(set(meth), expected_methods) except (xmlrpclib.ProtocolError, socket.error) as e: @@ -369,7 +374,7 @@ class SimpleServerTestCase(unittest.TestCase): def test_introspection2(self): try: # test _methodHelp() - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) divhelp = p.system.methodHelp('div') self.assertEqual(divhelp, 'This is the div function') except (xmlrpclib.ProtocolError, socket.error) as e: @@ -381,7 +386,7 @@ class SimpleServerTestCase(unittest.TestCase): def test_introspection3(self): try: # test native doc - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) myfunction = p.system.methodHelp('my_function') self.assertEqual(myfunction, 'This is my function') except (xmlrpclib.ProtocolError, socket.error) as e: @@ -394,7 +399,7 @@ class SimpleServerTestCase(unittest.TestCase): # the SimpleXMLRPCServer doesn't support signatures, but # at least check that we can try making the call try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) divsig = p.system.methodSignature('div') self.assertEqual(divsig, 'signatures not supported') except (xmlrpclib.ProtocolError, socket.error) as e: @@ -405,7 +410,7 @@ class SimpleServerTestCase(unittest.TestCase): def test_multicall(self): try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.add(2,3) multicall.pow(6,8) @@ -422,7 +427,7 @@ class SimpleServerTestCase(unittest.TestCase): def test_non_existing_multicall(self): try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) multicall = xmlrpclib.MultiCall(p) multicall.this_is_not_exists() result = multicall() @@ -491,7 +496,7 @@ class FailingServerTestCase(unittest.TestCase): # test a call that shouldn't fail just as a smoke test try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) self.assertEqual(p.pow(6,8), 6**8) except (xmlrpclib.ProtocolError, socket.error) as e: # ignore failures due to non-blocking socket 'unavailable' errors @@ -504,7 +509,7 @@ class FailingServerTestCase(unittest.TestCase): xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, socket.error) as e: # ignore failures due to non-blocking socket 'unavailable' errors @@ -524,7 +529,7 @@ class FailingServerTestCase(unittest.TestCase): xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = True try: - p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) + p = xmlrpclib.ServerProxy(URL) p.pow(6,8) except (xmlrpclib.ProtocolError, socket.error) as e: # ignore failures due to non-blocking socket 'unavailable' errors @@ -605,15 +610,9 @@ class CGIHandlerTestCase(unittest.TestCase): def test_main(): xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase, BinaryTestCase, FaultTestCase] - - # The test cases against a SimpleXMLRPCServer raise a socket error - # 10035 (WSAEWOULDBLOCK) in the server thread handle_request call when - # run on Windows. This only happens on the first test to run, but it - # fails every time and so these tests are skipped on win32 platforms. - if sys.platform != 'win32': - xmlrpc_tests.append(SimpleServerTestCase) - xmlrpc_tests.append(FailingServerTestCase) - xmlrpc_tests.append(CGIHandlerTestCase) + xmlrpc_tests.append(SimpleServerTestCase) + xmlrpc_tests.append(FailingServerTestCase) + xmlrpc_tests.append(CGIHandlerTestCase) support.run_unittest(*xmlrpc_tests) |