diff --git a/moli/tests/fetch_cli/xhr_timeout.rs b/moli/tests/fetch_cli/xhr_timeout.rs index f800b812b0b..4394af98fc9 100644 --- a/moli/tests/fetch_cli/xhr_timeout.rs +++ b/moli/tests/fetch_cli/xhr_timeout.rs @@ -5,7 +5,7 @@ use axum::{ body::{Body, Bytes}, extract::Query, response::Html, - routing::{get, post}, + routing::{get, options, post}, }; use std::{collections::HashMap, convert::Infallible, time::Duration}; @@ -68,15 +68,24 @@ async fn upload_response(Query(delays): Query>, body: Bytes })) } +async fn pending_upload_preflight() -> Body { + std::future::pending().await +} + #[test] fn xhr_upload_notifications_preserve_timeout_order_in_window_and_worker() -> Result<()> { let runtime = tokio::runtime::Builder::new_multi_thread() .worker_threads(32) .enable_all() .build()?; - let (url, server) = runtime.block_on(async { + let (url, server, pending_server) = runtime.block_on(async { let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; - let url = format!("http://{}/page", listener.local_addr()?); + let pending_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let pending_origin = format!("http://{}", pending_listener.local_addr()?); + let url = format!( + "http://{}/page?pendingOrigin={pending_origin}", + listener.local_addr()? + ); let app = Router::new() .route( "/page", @@ -84,7 +93,12 @@ fn xhr_upload_notifications_preserve_timeout_order_in_window_and_worker() -> Res ) .route("/upload", post(upload_response)); let server = tokio::spawn(async move { axum::serve(listener, app).await.unwrap() }); - Ok::<_, anyhow::Error>((url, server)) + // Hold the cross-origin preflight so these requests cannot upload, + // even if the script owner's busy task exceeds the reporting interval. + let pending_app = Router::new().route("/upload", options(pending_upload_preflight)); + let pending_server = + tokio::spawn(async move { axum::serve(pending_listener, pending_app).await.unwrap() }); + Ok::<_, anyhow::Error>((url, server, pending_server)) })?; let result = run_fetch_cli_with_args( &url, @@ -96,7 +110,9 @@ fn xhr_upload_notifications_preserve_timeout_order_in_window_and_worker() -> Res ], ); server.abort(); + pending_server.abort(); assert!(runtime.block_on(server).unwrap_err().is_cancelled()); + assert!(runtime.block_on(pending_server).unwrap_err().is_cancelled()); let output = result?; let stdout = clean_output(&output.stdout); assert!( diff --git a/moli/tests/fetch_cli/xhr_upload_timeout.html b/moli/tests/fetch_cli/xhr_upload_timeout.html index 8a432595d83..62cfda5cc28 100644 --- a/moli/tests/fetch_cli/xhr_upload_timeout.html +++ b/moli/tests/fetch_cli/xhr_upload_timeout.html @@ -1,10 +1,10 @@