mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use a shared file-system lock in `create_server` (#11294)
With parallel run of tests, one gets "Address already in use" errors as all tests attempt to bind to the same port. Fix it with a shared file-system lock. Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
@@ -93,6 +93,7 @@ test = [
|
|||||||
"pytest>=4.6",
|
"pytest>=4.6",
|
||||||
"html5lib",
|
"html5lib",
|
||||||
"cython",
|
"cython",
|
||||||
|
"filelock"
|
||||||
]
|
]
|
||||||
|
|
||||||
[[project.authors]]
|
[[project.authors]]
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ def test_defaults(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-too-many-retries', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-too-many-retries', freshenv=True)
|
||||||
def test_too_many_retries(app):
|
def test_too_many_retries(app):
|
||||||
|
with http_server(DefaultsHandler):
|
||||||
app.build()
|
app.build()
|
||||||
|
|
||||||
# Text output
|
# Text output
|
||||||
@@ -688,6 +689,7 @@ def test_get_after_head_raises_connection_error(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-documents_exclude', freshenv=True)
|
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-documents_exclude', freshenv=True)
|
||||||
def test_linkcheck_exclude_documents(app):
|
def test_linkcheck_exclude_documents(app):
|
||||||
|
with http_server(DefaultsHandler):
|
||||||
app.build()
|
app.build()
|
||||||
|
|
||||||
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
with open(app.outdir / 'output.json', encoding='utf-8') as fp:
|
||||||
|
|||||||
@@ -4,10 +4,16 @@ import pathlib
|
|||||||
import threading
|
import threading
|
||||||
from ssl import PROTOCOL_TLS_SERVER, SSLContext
|
from ssl import PROTOCOL_TLS_SERVER, SSLContext
|
||||||
|
|
||||||
|
import filelock
|
||||||
|
|
||||||
# Generated with:
|
# Generated with:
|
||||||
# $ openssl req -new -x509 -days 3650 -nodes -out cert.pem \
|
# $ openssl req -new -x509 -days 3650 -nodes -out cert.pem \
|
||||||
# -keyout cert.pem -addext "subjectAltName = DNS:localhost"
|
# -keyout cert.pem -addext "subjectAltName = DNS:localhost"
|
||||||
CERT_FILE = str(pathlib.Path(__file__).parent / "certs" / "cert.pem")
|
TESTS_ROOT = pathlib.Path(__file__).parent
|
||||||
|
CERT_FILE = str(TESTS_ROOT / "certs" / "cert.pem")
|
||||||
|
|
||||||
|
# File lock for tests
|
||||||
|
LOCK_PATH = str(TESTS_ROOT / 'test-server.lock')
|
||||||
|
|
||||||
|
|
||||||
class HttpServerThread(threading.Thread):
|
class HttpServerThread(threading.Thread):
|
||||||
@@ -34,6 +40,8 @@ class HttpsServerThread(HttpServerThread):
|
|||||||
|
|
||||||
def create_server(thread_class):
|
def create_server(thread_class):
|
||||||
def server(handler):
|
def server(handler):
|
||||||
|
lock = filelock.FileLock(LOCK_PATH)
|
||||||
|
with lock:
|
||||||
server_thread = thread_class(handler, daemon=True)
|
server_thread = thread_class(handler, daemon=True)
|
||||||
server_thread.start()
|
server_thread.start()
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user