Skip to content

Commit

Permalink
[CI/CD] implement readiness check before yielding local-http(s) test …
Browse files Browse the repository at this point in the history
…servers (#12050)

Co-authored-by: Bénédikt Tran <[email protected]>
  • Loading branch information
jayaddison and picnixz committed Mar 8, 2024
1 parent 1281b15 commit 1bfddf8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
10 changes: 8 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import http.server
import pathlib
import socket
import threading
from ssl import PROTOCOL_TLS_SERVER, SSLContext

Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 1bfddf8

Please sign in to comment.