From 1bfddf81e02177780a2525c8638b6081c273a336 Mon Sep 17 00:00:00 2001 From: James Addison <55152140+jayaddison@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:16:31 +0000 Subject: [PATCH] [CI/CD] implement readiness check before yielding local-http(s) test servers (#12050) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- CHANGES.rst | 3 +++ tests/utils.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d39895a9f..8de0fd00e 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 32636b793..c82c449db 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 @@ CERT_FILE = str(TESTS_ROOT / "certs" / "cert.pem") # 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 create_server(thread_class): 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)