test: align paired browser settle timing

This commit is contained in:
SGavrl committed 2026-07-26 14:41:10 +00:00
1 parent b03c663952
commit 9f33db610e
3 files changed
+40 -7

No files matched your search

+18 -5
View File
@@ -1242,11 +1242,24 @@ impl Page {
}
let hydration_snapshot = self.js.as_ref().and_then(capture_hydration_snapshot);
if let Some(js) = &mut self.js {
// Bounded against both async idle and synchronous microtask storms:
// a plain tokio timeout cannot preempt a page that pins the thread
// inside V8 (the real-world SPA hang), so settle drives the loop
// through the watchdog-guarded path.
let _ = js.run_event_loop_bounded(max_ms).await;
if std::env::var_os("OBSCURA_STRICT_SETTLE").is_some() {
// Paired browser measurements need the same wall-clock interval
// after load in both engines. The ordinary product path returns
// as soon as the loop is idle for speed; strict mode pumps all
// pending work, then retains the remaining wall-clock delay.
let started = tokio::time::Instant::now();
let _ = js.run_event_loop_bounded(max_ms).await;
let requested = tokio::time::Duration::from_millis(max_ms);
let elapsed = started.elapsed();
if elapsed < requested {
tokio::time::sleep(requested - elapsed).await;
}
} else {
// Bounded against both async idle and synchronous microtask
// storms: a plain tokio timeout cannot preempt a page that pins
// the thread inside V8, so settle uses the watchdog path.
let _ = js.run_event_loop_bounded(max_ms).await;
}
if let Some(before) = hydration_snapshot {
let _ = restore_hydration_snapshot_if_needed(js, before);
+12 -1
View File
@@ -970,7 +970,18 @@ async fn wait_for_selector(page: &mut Page, selector: &str, timeout_secs: u64) -
return false;
}
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
// The selector may be created by a timer, dynamic import, or fetch
// completion. Sleeping without pumping V8 makes those callbacks unable
// to run, so a valid selector wait always times out. Drive one bounded
// event-loop slice, then retain a 100ms polling cadence if it returned
// idle immediately.
let slice_started = tokio::time::Instant::now();
page.settle(100).await;
let spent = slice_started.elapsed();
let cadence = tokio::time::Duration::from_millis(100);
if spent < cadence {
tokio::time::sleep(cadence - spent).await;
}
}
}