mirror of
https://github.com/lexmount/moli.git
synced 2026-11-24 08:02:58 +00:00
test(core): stabilize shared readiness deadline coverage
This commit is contained in:
@@ -2609,29 +2609,28 @@ async fn best_effort_page_readiness_consumes_only_the_remaining_fetch_deadline()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[tokio::test]
|
||||
async fn page_fetch_wait_until_apis_do_not_restart_best_effort_timeout() -> Result<()> {
|
||||
let server = FixtureServer::spawn().await?;
|
||||
let browser = Browser::new(AppConfig::default())?;
|
||||
let url = server.url("/wait-until-shared-deadline");
|
||||
|
||||
for (wait_until, path) in [
|
||||
(
|
||||
RenderedDomWaitUntil::NetworkIdle,
|
||||
"/wait-until-slow-interval-fetch",
|
||||
),
|
||||
(
|
||||
RenderedDomWaitUntil::DomStable,
|
||||
"/wait-until-slow-interval-dom-mutation",
|
||||
),
|
||||
for wait_until in [
|
||||
RenderedDomWaitUntil::NetworkIdle,
|
||||
RenderedDomWaitUntil::DomStable,
|
||||
] {
|
||||
let started = std::time::Instant::now();
|
||||
let page = browser
|
||||
.fetch_with_wait_until(&server.url(path), wait_until, Duration::from_secs(1))
|
||||
// The main response spends four seconds of the ten-second budget.
|
||||
// The eight-second subresource stays pending on the shared budget
|
||||
// and has time to complete if readiness starts a fresh budget.
|
||||
let mut page = browser
|
||||
.fetch_with_wait_until(&url, wait_until, Duration::from_secs(10))
|
||||
.await?;
|
||||
|
||||
assert!(
|
||||
started.elapsed() < Duration::from_millis(1_300),
|
||||
"the Page-returning {wait_until:?} API appears to have started a fresh timeout"
|
||||
page.serialize_html_async()
|
||||
.await?
|
||||
.contains("data-activity=\"pending\""),
|
||||
"the Page-returning {wait_until:?} API waited for activity beyond the shared deadline"
|
||||
);
|
||||
page.close_async().await?;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,13 @@ const WAIT_UNTIL_INTERVAL_FETCH_HTML: &str = "<!doctype html><html><body data-st
|
||||
const WAIT_UNTIL_INTERVAL_DOM_MUTATION_HTML: &str = "<!doctype html><html><body data-state=\"init\"><main id=\"mutation-count\">0</main><script>window.addEventListener('load', () => { setInterval(() => { const count = Number(document.body.getAttribute('data-mutation-count') || '0') + 1; document.body.setAttribute('data-mutation-count', String(count)); document.getElementById('mutation-count').textContent = String(count); }, 50); });</script></body></html>";
|
||||
const WAIT_UNTIL_SLOW_STATIC_HTML: &str =
|
||||
"<!doctype html><html><body><main id=\"slow-main\">slow-main=ready</main></body></html>";
|
||||
const WAIT_UNTIL_SHARED_DEADLINE_HTML: &str = r#"<!doctype html><body data-activity="pending">
|
||||
<script>
|
||||
fetch('/wait-until-shared-deadline/activity')
|
||||
.then(response => response.text())
|
||||
.then(state => { document.body.dataset.activity = state; })
|
||||
.catch(() => {});
|
||||
</script></body>"#;
|
||||
const WAIT_UNTIL_REDIRECT_STATUS_NAVIGATION_HTML: &str = r#"<!doctype html>
|
||||
<html><head><title>terminal 302 navigation</title></head><body>
|
||||
<main id="redirect-status-challenge">redirect-status=challenge</main>
|
||||
@@ -355,6 +362,14 @@ pub(super) fn add_wait_routes(router: Router) -> Router {
|
||||
"/wait-until-slow-interval-dom-mutation",
|
||||
get(wait_until_slow_interval_dom_mutation_page),
|
||||
)
|
||||
.route(
|
||||
"/wait-until-shared-deadline",
|
||||
get(wait_until_shared_deadline_page),
|
||||
)
|
||||
.route(
|
||||
"/wait-until-shared-deadline/activity",
|
||||
get(wait_until_shared_deadline_activity),
|
||||
)
|
||||
.route(
|
||||
"/wait-until-redirect-status-navigation",
|
||||
get(wait_until_redirect_status_navigation_page),
|
||||
@@ -784,6 +799,16 @@ async fn wait_until_slow_interval_dom_mutation_page() -> Html<&'static str> {
|
||||
Html(WAIT_UNTIL_INTERVAL_DOM_MUTATION_HTML)
|
||||
}
|
||||
|
||||
async fn wait_until_shared_deadline_page() -> Html<&'static str> {
|
||||
sleep(Duration::from_secs(4)).await;
|
||||
Html(WAIT_UNTIL_SHARED_DEADLINE_HTML)
|
||||
}
|
||||
|
||||
async fn wait_until_shared_deadline_activity() -> &'static str {
|
||||
sleep(Duration::from_secs(8)).await;
|
||||
"complete"
|
||||
}
|
||||
|
||||
async fn wait_until_data_page() -> Response {
|
||||
(
|
||||
[(
|
||||
|
||||
Reference in New Issue
Block a user