Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP1:GA
python3-doc.24631
bpo37614-race_test_docxmlrpc_srv_setup.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File bpo37614-race_test_docxmlrpc_srv_setup.patch of Package python3-doc.24631
From 3911d8333c5b6f9374fa11ab7c912f1471580f0f Mon Sep 17 00:00:00 2001 From: Martin Panter <vadmium+py@gmail.com> Date: Thu, 18 Aug 2016 06:12:22 +0000 Subject: [PATCH] Issue #27614: Avoid race in test_docxmlrpc server setup --- Lib/test/test_docxmlrpc.py | 40 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -1,19 +1,17 @@ from xmlrpc.server import DocXMLRPCServer import http.client import sys +import unittest from test import support threading = support.import_module('threading') -import time -import socket -import unittest -PORT = None def make_request_and_skipIf(condition, reason): # If we skip the test, we have to make a request because # the server created in setUp blocks expecting one to come in. if not condition: return lambda func: func + def decorator(func): def make_request_and_skip(self): self.client.request("GET", "/") @@ -23,13 +21,10 @@ def make_request_and_skipIf(condition, r return decorator -def server(evt, numrequests): +def make_server(): serv = DocXMLRPCServer(("localhost", 0), logRequests=False) try: - global PORT - PORT = serv.socket.getsockname()[1] - # Add some documentation serv.set_server_title("DocXMLRPCServer Test Documentation") serv.set_server_name("DocXMLRPCServer Test Docs") @@ -67,41 +62,31 @@ def server(evt, numrequests): serv.register_function(annotation) serv.register_instance(ClassWithAnnotation()) - while numrequests > 0: - serv.handle_request() - numrequests -= 1 - except socket.timeout: - pass - finally: + return serv + except: serv.server_close() - PORT = None - evt.set() + raise class DocXMLRPCHTTPGETServer(unittest.TestCase): def setUp(self): - self._threads = support.threading_setup() # Enable server feedback DocXMLRPCServer._send_traceback_header = True - self.evt = threading.Event() - threading.Thread(target=server, args=(self.evt, 1)).start() - - # wait for port to be assigned - n = 1000 - while n > 0 and PORT is None: - time.sleep(0.001) - n -= 1 + self.serv = make_server() + self.thread = threading.Thread(target=self.serv.serve_forever) + self.thread.start() + PORT = self.serv.server_address[1] self.client = http.client.HTTPConnection("localhost:%d" % PORT) def tearDown(self): self.client.close() - self.evt.wait() - # Disable server feedback DocXMLRPCServer._send_traceback_header = False - support.threading_cleanup(*self._threads) + self.serv.shutdown() + self.thread.join() + self.serv.server_close def test_valid_get_response(self): self.client.request("GET", "/")
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor