diff --git a/CHANGES.rst b/CHANGES.rst index d39895a9f29..8de0fd00ebb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -90,6 +90,9 @@ Bugs fixed Patch by Bénédikt Tran. * #12008: Fix case-sensitive lookup of ``std:label`` names in intersphinx inventory. Patch by Michael Goerz. +* #12038: Resolve ``linkcheck`` unit test timeouts on Windows by adding a readiness + check to the test HTTP(S) server setup code. + Patch by James Addison. Testing ------- diff --git a/tests/utils.py b/tests/utils.py index 32636b7936c..c82c449dbde 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,6 +1,7 @@ import contextlib import http.server import pathlib +import socket import threading from ssl import PROTOCOL_TLS_SERVER, SSLContext @@ -15,11 +16,15 @@ # File lock for tests LOCK_PATH = str(TESTS_ROOT / 'test-server.lock') +HOST_NAME = "localhost" +HOST_PORT = 7777 +ADDRESS = (HOST_NAME, HOST_PORT) + class HttpServerThread(threading.Thread): def __init__(self, handler, *args, **kwargs): super().__init__(*args, **kwargs) - self.server = http.server.ThreadingHTTPServer(("localhost", 7777), handler) + self.server = http.server.ThreadingHTTPServer(ADDRESS, handler) def run(self): self.server.serve_forever(poll_interval=0.001) @@ -45,7 +50,8 @@ def server(handler): server_thread = thread_class(handler, daemon=True) server_thread.start() try: - yield server_thread + socket.create_connection(ADDRESS, timeout=0.5).close() # Attempt connection. + yield server_thread # Connection has been confirmed possible; proceed. finally: server_thread.terminate() return contextlib.contextmanager(server)