mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
[CI/CD] implement readiness check before yielding local-http(s) test servers (#12050)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
1281b158b4
commit
1bfddf81e0
@ -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
|
||||
-------
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user