Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: implement readiness check before yielding local-http(s) test servers #12050

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
396b8df
tests: increase timeout for linkcheck local-https test server
jayaddison Mar 7, 2024
cf50d4c
Revert "tests: increase timeout for linkcheck local-https test server"
jayaddison Mar 7, 2024
911d9c9
tests: implement socket-based healthcheck before yielding test HTTP(S…
jayaddison Mar 7, 2024
c3075c5
tests: update error message for non-responsive test server: healthche…
jayaddison Mar 7, 2024
34c2527
tests: remove fairly-redundant exception re-raise logic
jayaddison Mar 7, 2024
813c23c
tests: resource cleanup: close the readiness-check client socket
jayaddison Mar 7, 2024
912b55e
tests: refactor-out single-use variable
jayaddison Mar 7, 2024
cf149ad
tests: test server setup: add explanatory comment
jayaddison Mar 7, 2024
8c3751e
Add CHANGES.rst entry
jayaddison Mar 7, 2024
4364c6c
ci: run a matrix of Windows tests, and temporarily disable Ubuntu tests
jayaddison Mar 7, 2024
6bb4797
ci: fixup: relocate temporary 'if' condition
jayaddison Mar 7, 2024
95dd097
Code review: change variable name 'HOST' to 'ADDRESS'
jayaddison Mar 7, 2024
9720039
Code review: use a context-manager to handle client socket connection…
jayaddison Mar 7, 2024
1442999
Revert "Code review: use a context-manager to handle client socket co…
jayaddison Mar 7, 2024
6b2f11b
tests: attempt to improve commentary and link it more closely with th…
jayaddison Mar 7, 2024
df5687e
Revert "ci: fixup: relocate temporary 'if' condition"
jayaddison Mar 7, 2024
ed1144d
Revert "ci: run a matrix of Windows tests, and temporarily disable Ub…
jayaddison Mar 7, 2024
7719f1c
tests: nitpick: add full-stops to comment sentences (despite their qu…
jayaddison Mar 7, 2024
ea77de2
tests: nitpick: capitalize comment sentences.
jayaddison Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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