Skip to content

Commit 59860be

Browse files
committed
test: use ThreadingHTTPServer for browser-facing test servers
Single-threaded http.server.HTTPServer blocks its only thread in rfile.readline() on the first connection it accepts. Chrome (especially under --site-per-process) opens speculative/preconnect sockets without immediately sending a request, so the server can stall on an idle socket and never serve the real page request — Page.navigate then hangs the full 60s and fails with CommandExecutionTimeout (seen on Windows CI for the cross-origin OOPIF test). Switch every browser-facing test server to ThreadingHTTPServer so each connection gets its own thread and idle/speculative sockets can't starve real requests.
1 parent b074fba commit 59860be

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

tests/integration/test_nested_oopif_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def __init__(self, *a, **kw):
4949

5050
return H
5151

52-
srv_a = http.server.HTTPServer(('127.0.0.1', 0), _handler())
53-
srv_b = http.server.HTTPServer(('127.0.0.1', 0), _handler())
52+
srv_a = http.server.ThreadingHTTPServer(('127.0.0.1', 0), _handler())
53+
srv_b = http.server.ThreadingHTTPServer(('127.0.0.1', 0), _handler())
5454
port_a = srv_a.server_address[1]
5555
port_b = srv_b.server_address[1]
5656

tests/integration/test_tab_io_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Real-Chrome integration tests for Tab I/O over a local HTTP server.
22
3-
A throwaway ``HTTPServer`` serves a small page wired to external assets (CSS with
3+
A throwaway ``ThreadingHTTPServer`` serves a small page wired to external assets (CSS with
44
a ``url()`` background, JS and images) plus a downloadable attachment. Against it
55
we exercise the heavy I/O paths that need a real origin and real network
66
fetches: ``save_bundle`` (both rewrite and inline modes), ``expect_download``
@@ -16,7 +16,7 @@
1616
import socket
1717
import threading
1818
import zipfile
19-
from http.server import BaseHTTPRequestHandler, HTTPServer
19+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
2020
from pathlib import Path
2121

2222
import pytest
@@ -89,7 +89,7 @@ def log_message(self, *args):
8989

9090
def _serve(handler_cls):
9191
port = _find_free_port()
92-
server = HTTPServer(('127.0.0.1', port), handler_cls)
92+
server = ThreadingHTTPServer(('127.0.0.1', port), handler_cls)
9393
thread = threading.Thread(target=server.serve_forever, daemon=True)
9494
thread.start()
9595
return server, thread, f'http://127.0.0.1:{port}'

tests/integration/test_tab_request_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import json
1212
import socket
1313
import threading
14-
from http.server import BaseHTTPRequestHandler, HTTPServer
14+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
1515
from urllib.parse import parse_qs, urlparse
1616

1717
import pytest
@@ -170,7 +170,7 @@ def log_message(self, *args):
170170
@pytest_asyncio.fixture
171171
async def request_tab(ci_chrome_options):
172172
port = _find_free_port()
173-
server = HTTPServer(('127.0.0.1', port), _RequestHandler)
173+
server = ThreadingHTTPServer(('127.0.0.1', port), _RequestHandler)
174174
thread = threading.Thread(target=server.serve_forever, daemon=True)
175175
thread.start()
176176
base = f'http://127.0.0.1:{port}'

tests/integration/test_worker_user_agent_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _Handler(_SilentHandler):
5555
def __init__(self, *args, **kwargs):
5656
super().__init__(*args, directory=str(PAGES_DIR), **kwargs)
5757

58-
server = http.server.HTTPServer(('127.0.0.1', 0), _Handler)
58+
server = http.server.ThreadingHTTPServer(('127.0.0.1', 0), _Handler)
5959
port = server.server_address[1]
6060
threading.Thread(target=server.serve_forever, daemon=True).start()
6161
_wait_for_server('127.0.0.1', port)

0 commit comments

Comments
 (0)