tests: a fixed pause before a read is a wait for the condition the read needs, with a deadline of 30 s
This commit is contained in:
1 parent
23eee4a1db
commit
258a803f11
9 files changed
+68
-34
No files matched your search
@@ -94,7 +94,9 @@ def test_the_client_hears_the_document_and_the_fetches_and_no_preflight(firefox_
|
||||
page = context.new_page()
|
||||
page.on("request", lambda r: heard.append((r.method, r.url.rsplit("/", 1)[-1] or "page")))
|
||||
page.goto(two_origins, wait_until="load")
|
||||
pump = lambda: page.wait_for_timeout(100) # the events of a sync client are delivered while it calls the browser
|
||||
def pump():
|
||||
page.wait_for_timeout(100) # the events of a sync client are delivered while it calls the browser
|
||||
|
||||
# The fetches are the page's own; each one's preflight reaches the server BEFORE its GET, so once the server
|
||||
# has seen both GETs every OPTIONS the browser would make has been made.
|
||||
assert wait_until(lambda: sum(1 for m, _ in list(_Api.hits) if m == "GET") >= 2, 30, pump), (
|
||||
|
||||
@@ -10,6 +10,7 @@ from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from _waits import wait_until
|
||||
from stroke_shape import stroke_problems
|
||||
|
||||
PAGE = """<!doctype html><html><body style="margin:0">
|
||||
@@ -44,7 +45,6 @@ def test_a_stroke_from_standstill_does_not_open_with_the_point_it_stands_on(fire
|
||||
"""After a move that stopped on (500, 300) and a pause, the click's stroke
|
||||
begins at its first real step: the page's next `mousemove` is not (500, 300)
|
||||
again."""
|
||||
import time
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
with InvisiblePlaywright(seed=4252, binary_path=firefox_binary, headless=True,
|
||||
@@ -52,7 +52,9 @@ def test_a_stroke_from_standstill_does_not_open_with_the_point_it_stands_on(fire
|
||||
page = browser.new_context().new_page()
|
||||
page.set_content(PAGE)
|
||||
page.mouse.move(500, 300)
|
||||
time.sleep(0.3)
|
||||
# until the page has heard the move end on its point (a condition with a deadline, not 0.3 s): the click below starts from a pointer at rest
|
||||
assert wait_until(lambda: (page.evaluate("window.moves") or [None])[-1] == [500, 300], 30,
|
||||
lambda: page.wait_for_timeout(50)), page.evaluate("window.moves")
|
||||
seen = len(page.evaluate("window.moves"))
|
||||
assert page.evaluate("window.moves")[-1] == [500, 300]
|
||||
page.mouse.click(400, 240)
|
||||
|
||||
@@ -13,7 +13,7 @@ knows the names used here, so a page loads only if the lookup went to the DoH).
|
||||
measures). In global mode 0 `TRRService::GetRequestTimeout` returns `network.trr.request_timeout_ms` (1.5 s); in global
|
||||
mode 3 it returns `network.trr.request_timeout_mode_trronly_ms` (30 s). A request made TRR_ONLY per request under a global
|
||||
mode 0 would keep the 1.5 s one and fail a lookup whose answer is only 2 s away, with nothing to fall back to. The page
|
||||
must load, within 20 s, and the FakeDoh log must show the queries answered after the delay.
|
||||
must load, within 30 s, and the FakeDoh log must show the queries answered after the delay.
|
||||
* `test_a_name_the_doh_refused_once_resolves_on_the_next_request`: the FakeDoh refuses the FIRST query of each type for
|
||||
`flaky-a.test` by ending the exchange with no answer (a reset h2 stream: a failure of the CHANNEL, the kind
|
||||
`ConfirmationContext::RecordTRRStatus` counts; `_doh_servers.FAILURE_KINDS` has the other two) and serves it afterwards.
|
||||
@@ -48,13 +48,13 @@ pytestmark = pytest.mark.e2e
|
||||
|
||||
#: The latency of the slow DoH, and what a page behind it may take at most.
|
||||
DOH_LATENCY_S = 2.0
|
||||
SLOW_LOAD_LIMIT_S = 20.0
|
||||
SLOW_LOAD_LIMIT_S = 30.0
|
||||
#: The retries after a refusal: how many and how far apart (more than the 1 s negative cache). The loop is a COUNT of navigations, so
|
||||
#: a runner that stalls for seconds between two of them lengthens the test and never takes an attempt away from it.
|
||||
RETRIES = 5
|
||||
RETRY_GAP_S = 2.0
|
||||
#: What one navigation of that loop may take: far beyond any healthy run (the product's own limits are 1.5 s for a DoH request and
|
||||
#: the 20 s of the slow page); a navigation that reaches it is a page that never ends, and is reported as that attempt's error.
|
||||
#: the 30 s of the slow page); a navigation that reaches it is a page that never ends, and is reported as that attempt's error.
|
||||
NAVIGATION_LIMIT_MS = 30000
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ def _only_the_doh_road_was_used(doh, gw, watcher):
|
||||
def test_a_slow_doh_still_resolves_the_name_of_a_proxied_context(firefox_binary, doh, pages, gateway, watcher,
|
||||
record_property):
|
||||
"""`slow-a.test` is known only to the FakeDoh, which answers it 2 s after the query. The page of a context with a
|
||||
proxy of its own must load within 20 s, reached by address through that proxy."""
|
||||
proxy of its own must load within 30 s, reached by address through that proxy."""
|
||||
doh.names["slow-a.test"] = "127.0.0.1"
|
||||
doh.delay_names["slow-a.test"] = DOH_LATENCY_S
|
||||
gw = gateway("gw")
|
||||
@@ -142,7 +142,6 @@ def test_a_slow_doh_still_resolves_the_name_of_a_proxied_context(firefox_binary,
|
||||
"the page behind a DoH that answers in %.0f s did not load (%s): the DoH request of a lookup made TRR_ONLY per "
|
||||
"request gave up before the answer (the 1.5 s timeout of global mode 0?)" % (DOH_LATENCY_S, error) + why)
|
||||
assert "HOST=slow-a.test:%d" % pages.port in text, "the page is not the page of the name: %r" % text + why
|
||||
assert seconds < SLOW_LOAD_LIMIT_S, "the page took %.1f s to load, the limit is %.0f s" % (seconds, SLOW_LOAD_LIMIT_S) + why
|
||||
assert seconds >= DOH_LATENCY_S - 0.2, (
|
||||
"the page loaded in %.2f s, before the DoH could have answered (%.0f s): the name was not resolved by it"
|
||||
% (seconds, DOH_LATENCY_S) + why)
|
||||
@@ -183,7 +182,9 @@ def test_a_name_the_doh_refused_once_resolves_on_the_next_request(firefox_binary
|
||||
context, page = _page_in(browser, proxy=gw.proxy)
|
||||
page.close()
|
||||
attempts.append(_navigate(context, url, NAVIGATION_LIMIT_MS))
|
||||
while attempts[-1][0] is None and len(attempts) <= RETRIES:
|
||||
for _retry in range(RETRIES):
|
||||
if attempts[-1][0] is not None:
|
||||
break
|
||||
time.sleep(RETRY_GAP_S)
|
||||
attempts.append(_navigate(context, url, NAVIGATION_LIMIT_MS))
|
||||
context.close()
|
||||
|
||||
@@ -68,9 +68,14 @@ import time
|
||||
|
||||
import pytest
|
||||
|
||||
from _waits import awatch
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
HELD_S = 1.5
|
||||
#: The deadline of every wait for a thing that must happen (the stop of a goto the server holds, the page it lands on): a goto that nothing stops ends at
|
||||
#: it with another error, so it is the bound of the wait that leads up to the stop and no healthy run comes near it.
|
||||
GOTO_TIMEOUT_MS = 30_000
|
||||
ACT = {
|
||||
"docopen": "document.open(); document.write('<html><body><h1>rewritten</h1></body></html>'); document.close();",
|
||||
"stop": "window.stop();",
|
||||
@@ -201,7 +206,7 @@ def test_a_goto_stopped_on_its_way_raises_or_lands_and_never_lies(firefox_binary
|
||||
began = time.monotonic()
|
||||
error = None
|
||||
try:
|
||||
page.goto(target, wait_until="domcontentloaded", timeout=10_000)
|
||||
page.goto(target, wait_until="domcontentloaded", timeout=GOTO_TIMEOUT_MS)
|
||||
except Error as e:
|
||||
error = e.message
|
||||
finally:
|
||||
@@ -217,7 +222,7 @@ def test_a_goto_stopped_on_its_way_raises_or_lands_and_never_lies(firefox_binary
|
||||
expected = same + end
|
||||
if end in ("/old", "/start"):
|
||||
expected = same + "%s?k=%s&i=%d" % (end, kind, i)
|
||||
page.wait_for_url(expected, timeout=5_000)
|
||||
page.wait_for_url(expected, timeout=GOTO_TIMEOUT_MS)
|
||||
else:
|
||||
assert error is None, where
|
||||
# It waited for its page, which the server held.
|
||||
@@ -248,17 +253,16 @@ def test_a_second_goto_interrupts_the_first_and_lands(firefox_binary, server):
|
||||
# the gate, after both gotos have returned: the first can only
|
||||
# end by being replaced.
|
||||
gate = GATES["first=%d" % i] = threading.Event()
|
||||
began = time.monotonic()
|
||||
|
||||
async def go(url, after=None):
|
||||
# The second goto starts once the server has the first's
|
||||
# request, so the first is on its way on any machine. The
|
||||
# first goto's own timeout is the bound of the wait.
|
||||
while after is not None and after not in ARRIVED:
|
||||
assert time.monotonic() - began < 10, "the first goto never left"
|
||||
await asyncio.sleep(0.02)
|
||||
if after is not None:
|
||||
left = await awatch(lambda: after in ARRIVED, bool, GOTO_TIMEOUT_MS / 1000, lambda: asyncio.sleep(0.02))
|
||||
assert left.ok, "the first goto never left: %s" % left.render()
|
||||
try:
|
||||
await page.goto(url, wait_until="domcontentloaded", timeout=10_000)
|
||||
await page.goto(url, wait_until="domcontentloaded", timeout=GOTO_TIMEOUT_MS)
|
||||
return None
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
@@ -133,10 +133,12 @@ def test_hidden_desktop_takes_the_window_off_screen_but_keeps_rendering(firefox_
|
||||
with ip as browser:
|
||||
page = browser.new_page()
|
||||
page.goto(served, timeout=30_000)
|
||||
time.sleep(2)
|
||||
|
||||
desktop = ip._virtual_display.name
|
||||
assert desktop and desktop != "Default"
|
||||
# until the window is on its own desktop (a condition with a deadline, not 2 s): the check that none is on the caller's desktop is read
|
||||
# after the window exists, so it cannot be read before the window had a place to be put in; a session that never puts one there ends red below
|
||||
wait_until(lambda: _moz_windows_on(desktop, ip) >= 1, 30, lambda: page.wait_for_timeout(100))
|
||||
|
||||
# 1) not on the desktop the caller is on ...
|
||||
assert _moz_windows_on(None, ip) == 0, (
|
||||
@@ -165,13 +167,13 @@ def test_hidden_desktop_takes_the_window_off_screen_but_keeps_rendering(firefox_
|
||||
# line that makes the engine's release gate prove it per build.
|
||||
stream = Stream("hidden desktop")
|
||||
stream.start(page)
|
||||
deadline = time.time() + 15
|
||||
deadline = time.time() + 30
|
||||
while not stream.frames and time.time() < deadline:
|
||||
time.sleep(0.1)
|
||||
page.screencast.stop()
|
||||
frames = stream.frames
|
||||
assert frames, ("no screencast frame arrived from the hidden desktop "
|
||||
"in 15 s: the window capturer is not being used there\n"
|
||||
"in 30 s: the window capturer is not being used there\n"
|
||||
"%s\n"
|
||||
"engine output (lines starting with 'screencast:'):\n%s"
|
||||
% (stream.describe(), engine_screencast_lines(page)))
|
||||
|
||||
@@ -73,11 +73,14 @@ function arrivedFromOutside(el, label) {
|
||||
const WATCHED = ['b', 'l', 'i'].map(id => document.getElementById(id));
|
||||
WATCHED.forEach(remember);
|
||||
|
||||
// The watcher counts its own looks (`window.__looks`), so a test that wants a look made AFTER something it did waits for the counter to move, not for a time.
|
||||
window.__looks = 0;
|
||||
setInterval(() => {
|
||||
const f = [];
|
||||
WATCHED.forEach((el, n) => f.push(...arrivedFromOutside(el, 'el' + n)));
|
||||
document.getElementById('verdict').textContent =
|
||||
f.length ? ('DIRTY ' + f.join(' ')) : 'clean';
|
||||
window.__looks += 1;
|
||||
}, 50);
|
||||
|
||||
// ⛔ THE CONTROL FOR THE WATCHER ITSELF. The page stamps a fresh element with
|
||||
@@ -172,8 +175,12 @@ def test_the_aria_snapshot_writes_nothing_the_page_can_see(firefox_binary):
|
||||
call = ("(injected, o) => injected.ariaSnapshot("
|
||||
"document.documentElement, o)")
|
||||
|
||||
looks_before = page.evaluate("window.__looks")
|
||||
snapshot = d.injected.call(frame, call, {"mode": "ai"})
|
||||
page.wait_for_timeout(200)
|
||||
# until the watcher has looked twice more (a condition with a deadline, not 200 ms): the second look began after the call above had returned,
|
||||
# so the verdict read below is of the page as the snapshot left it. A watcher that stops ends red at the deadline.
|
||||
assert wait_until(lambda: page.evaluate("window.__looks") >= looks_before + 2, 30, lambda: page.wait_for_timeout(50)), (
|
||||
"the watcher of the page did not look again after the snapshot: its verdict below would be of the page before it")
|
||||
|
||||
# ⛔ THE BRANCH HAS TO HAVE RUN, or this test goes green on a build
|
||||
# where nothing was written and says nothing about confinement. `ref=`
|
||||
@@ -208,14 +215,18 @@ def test_the_default_path_does_not_even_write_in_the_sandbox(firefox_binary):
|
||||
seed=42, binary_path=firefox_binary) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto(site.url)
|
||||
page.wait_for_timeout(200)
|
||||
# until the watcher has looked once (a condition with a deadline, not 200 ms)
|
||||
assert wait_until(lambda: page.evaluate("window.__looks") >= 1, 30, lambda: page.wait_for_timeout(50)), "the watcher of the page never ran"
|
||||
|
||||
d = _page_dispatcher(page)
|
||||
frame = d.actions.lifecycle.main_frame
|
||||
looks_before = page.evaluate("window.__looks")
|
||||
d.injected.call(frame,
|
||||
"(injected, o) => injected.ariaSnapshot("
|
||||
"document.documentElement, o)", {"mode": "raw"})
|
||||
page.wait_for_timeout(200)
|
||||
# until it has looked twice more (the second look began after the call returned), not 200 ms: the verdict below is of the page as the call left it
|
||||
assert wait_until(lambda: page.evaluate("window.__looks") >= looks_before + 2, 30, lambda: page.wait_for_timeout(50)), (
|
||||
"the watcher of the page did not look again after the call")
|
||||
|
||||
from_sandbox = d.injected.evaluate(
|
||||
frame, "(() => { const el = document.getElementById('b');"
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_the_four_states_are_reached_on_a_real_page(firefox_binary):
|
||||
{"removeOnDetach": True})
|
||||
page = c.send("Browser.newPage",
|
||||
{"browserContextId": ctx["browserContextId"]})
|
||||
deadline = time.time() + 15
|
||||
deadline = time.time() + 30
|
||||
while page["targetId"] not in sessions and time.time() < deadline:
|
||||
time.sleep(0.02)
|
||||
v = sessions[page["targetId"]]
|
||||
@@ -84,8 +84,8 @@ def test_the_four_states_are_reached_on_a_real_page(firefox_binary):
|
||||
assert v.inflight == 0
|
||||
|
||||
tree = v.frame_tree()
|
||||
children = [d for d in tree.values() if d["parent"]]
|
||||
assert len(children) == 1, tree
|
||||
iframes = [d for d in tree.values() if d["parent"]] # the frames of the page's tree: its one <iframe>, not a count of processes
|
||||
assert len(iframes) == 1, tree
|
||||
assert "load" in tree[v.main_frame]["states"]
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
@@ -15,7 +15,17 @@ import pytest
|
||||
TYPE = re.compile(r"Setting remoteType of process (\d+) to (\S+)")
|
||||
|
||||
|
||||
def _remote_types(tmp_path, binary, **option):
|
||||
def _read_types(tmp_path, base):
|
||||
types = []
|
||||
for path in sorted(tmp_path.glob(base.name + "*")):
|
||||
types += [m.group(2) for m in TYPE.finditer(path.read_text(encoding="utf-8", errors="replace"))]
|
||||
return types
|
||||
|
||||
|
||||
def _remote_types(tmp_path, binary, until, window=0.0, **option):
|
||||
"""The types of the processes the engine made. It waits (30 s) until ``until(types)`` holds, which is the positive thing the verdict needs to read, and then leaves
|
||||
``window`` seconds in which a process that must NOT be born could show: that window looks for something that must not happen, so a slow machine can only make it weaker."""
|
||||
from _waits import wait_until
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
mp = pytest.MonkeyPatch()
|
||||
@@ -27,18 +37,16 @@ def _remote_types(tmp_path, binary, **option):
|
||||
timezone="America/New_York", **option) as browser:
|
||||
page = browser.new_context().new_page()
|
||||
page.goto("about:blank")
|
||||
time.sleep(10)
|
||||
wait_until(lambda: until(_read_types(tmp_path, base)), 30, lambda: page.wait_for_timeout(100))
|
||||
time.sleep(window)
|
||||
finally:
|
||||
mp.undo()
|
||||
types = []
|
||||
for path in sorted(tmp_path.glob(base.name + "*")):
|
||||
types += [m.group(2) for m in TYPE.finditer(path.read_text(encoding="utf-8", errors="replace"))]
|
||||
return types
|
||||
return _read_types(tmp_path, base)
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_without_the_option_the_new_tab_page_is_preloaded_in_its_own_process(firefox_binary, tmp_path):
|
||||
types = _remote_types(tmp_path, firefox_binary)
|
||||
types = _remote_types(tmp_path, firefox_binary, lambda found: "privilegedabout" in found)
|
||||
assert types, "the engine wrote no line about its processes: the control cannot judge"
|
||||
assert "privilegedabout" in types, "the retail keeps the New Tab page preloaded: %s" % sorted(set(types))
|
||||
|
||||
@@ -49,6 +57,6 @@ def test_asked_to_turn_the_preload_off_there_is_no_privileged_about_process(fire
|
||||
|
||||
if "preload_newtab" not in inspect.signature(core_prefs.compose_session_prefs).parameters:
|
||||
pytest.skip("this core does not know preload_newtab yet")
|
||||
types = _remote_types(tmp_path, firefox_binary, preload_newtab=False)
|
||||
types = _remote_types(tmp_path, firefox_binary, bool, window=10, preload_newtab=False)
|
||||
assert types, "the engine wrote no line about its processes: the control cannot judge"
|
||||
assert "privilegedabout" not in types, "a process of the preloaded New Tab page was born: %s" % sorted(set(types))
|
||||
@@ -197,7 +197,11 @@ def shots(tmp_path_factory, firefox_binary):
|
||||
# reads back where it actually went rather than assuming, which
|
||||
# is the same mistake in miniature as the defect it covers.
|
||||
page.evaluate("() => window.scrollTo(1400, 0)")
|
||||
page.wait_for_timeout(300)
|
||||
# until the page IS where the clamp puts it (the scrollable width, at most 1400), not 300 ms; if it never lands, `landed` below is
|
||||
# read at the deadline and the assertions on it say so
|
||||
wait_until(lambda: page.evaluate(
|
||||
"() => Math.round(window.scrollX) === Math.round(Math.min(1400, document.documentElement.scrollWidth"
|
||||
" - document.documentElement.clientWidth))"), 30, lambda: page.wait_for_timeout(50))
|
||||
landed = page.evaluate("() => Math.round(window.scrollX)")
|
||||
page.screenshot(path=str(out / "sideways.png"))
|
||||
wide = page.evaluate(
|
||||
|
||||
Reference in new issue
Block a user