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:
vh
2026-09-23 19:05:12 -07:00
parent 20f1cb8594
commit ca0641f55b
3 changed files with 86 additions and 2 deletions
+20
View File
@@ -262,3 +262,23 @@ old = '''
.blurred-thumb{filter:blur(16px)}'''
new = '''
.blurred-thumb{filter:blur(0px)}'''
# ---- the flake: the test browser has no internet (positive control per file)
[[mutation]]
label = "the flow test browser can reach the internet (Google Fonts can stall networkidle)"
file = "tests/test_flow_browser.py"
test = "tests/test_flow_browser.py::test_the_test_browser_has_no_internet"
old = '''
b = pw.chromium.launch(args=OFFLINE)'''
new = '''
b = pw.chromium.launch()'''
[[mutation]]
label = "the embed test browser can reach the internet"
file = "tests/test_embed_browser.py"
test = "tests/test_embed_browser.py::test_the_test_browser_has_no_internet"
old = '''
b = pw.chromium.launch(args=OFFLINE)'''
new = '''
b = pw.chromium.launch()'''
+33 -1
View File
@@ -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
+33 -1
View File
@@ -24,11 +24,22 @@ playwright_api = pytest.importorskip("playwright.sync_api", reason="playwright i
PNG = b"\x89PNG\r\n\x1a\n"
# 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
@@ -773,3 +784,24 @@ def test_the_review_and_doc_top_bars_fit_a_phone(browser, live):
'.vbar button, .vbar .vbtn')].filter(e => e.offsetParent).map(e => e.getBoundingClientRect().height)) - 40""")
page.close()
assert all(v <= 0 for v in over.values()), over
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