test: the browser tests run with no internet
Every Booth page asks fonts.googleapis.com for its faces, and wait_until="networkidle" waits for that request. A stalled request to Google therefore held a page until goto's 30s timeout. That is the failure the full-suite flake shows: Page.goto timeouts in tests far apart within one run. A stalled font request reproduces it exactly. Whether that was THE cause is not proven: - 23 traced runs went green, against 1 red in 8 untraced; - no trace captured the pending request. A test that depends on Google being reachable is wrong regardless. Both browser fixtures now launch Chromium with every hostname but 127.0.0.1 failing DNS at once. Pages fall back to the system font stacks the tokens declare. Positive control in each file: an external host fails with ERR_NAME_NOT_RESOLVED in under 3s, and a Booth page still goes idle. Mutation-proved (r2b.toml 28/28). 776 passed.
This commit is contained in:
@@ -31,11 +31,22 @@ playwright_api = pytest.importorskip(
|
||||
)
|
||||
|
||||
|
||||
# NO INTERNET for the test browser. Every Booth page asks fonts.googleapis.com
|
||||
# for its faces, and "networkidle" waits for that request — so a stalled request
|
||||
# to Google hung the page until goto's 30s timeout, the failure mode of the
|
||||
# full-suite flake (Page.goto timeouts in tests far apart in one run; a stalled
|
||||
# font request reproduces it exactly). Whether that was THE cause is unproven;
|
||||
# a test that depends on Google being reachable is wrong regardless. Every
|
||||
# hostname but 127.0.0.1 now fails DNS at once, and the pages fall back to the
|
||||
# system stacks the tokens declare. Positive control: test_*_has_no_internet.
|
||||
OFFLINE = ["--host-resolver-rules=MAP * ~NOTFOUND , EXCLUDE 127.0.0.1"]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def browser():
|
||||
with playwright_api.sync_playwright() as pw:
|
||||
try:
|
||||
b = pw.chromium.launch()
|
||||
b = pw.chromium.launch(args=OFFLINE)
|
||||
except Exception as exc: # noqa: BLE001 - any launch failure is a skip
|
||||
pytest.skip(f"no usable chromium: {exc}")
|
||||
yield b
|
||||
@@ -638,3 +649,24 @@ def test_the_keyboard_flag_actually_submits(browser, live):
|
||||
|
||||
assert flagged == 1, f"the f key flagged {flagged} items, expected 1"
|
||||
assert survived, "the flag reloaded the page; in-place judgment must not"
|
||||
|
||||
|
||||
def test_the_test_browser_has_no_internet(browser, live):
|
||||
"""Positive control for OFFLINE (booth-dev's ask: see the fix in force,
|
||||
don't assume it). An external host fails at once, and a Booth page — whose
|
||||
fonts are external — still goes idle in well under the goto timeout."""
|
||||
base, root = live
|
||||
(root / "g").mkdir()
|
||||
page = browser.new_page()
|
||||
t = time.time()
|
||||
with pytest.raises(Exception) as err:
|
||||
page.goto("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans", timeout=10000)
|
||||
external = time.time() - t
|
||||
page.close()
|
||||
page = browser.new_page()
|
||||
t = time.time()
|
||||
page.goto(f"{base}/b/g/", wait_until="networkidle")
|
||||
local = time.time() - t
|
||||
page.close()
|
||||
assert "ERR_NAME_NOT_RESOLVED" in str(err.value) and external < 3, (str(err.value)[:80], external)
|
||||
assert local < 10, local
|
||||
|
||||
Reference in New Issue
Block a user