From e021ba473089609265419e70b3f39169f6a5f595 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 7 Dec 2024 00:06:48 +0100 Subject: [PATCH] Add `WASM_BINDGEN_TEST_DRIVER_TIMEOUT` (#4320) --- CHANGELOG.md | 11 +++++++---- .../src/bin/wasm-bindgen-test-runner/headless.rs | 11 ++++++++--- .../cli/src/bin/wasm-bindgen-test-runner/main.rs | 14 +++++++++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7181e5310c1..c2e4d998d8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,17 +5,20 @@ ### Added +* Add clear error message to communicate new feature resolver version requirements. + [#4312](https://github.com/rustwasm/wasm-bindgen/pull/4312) + * Add support for multi-threading in Node.js. [#4318](https://github.com/rustwasm/wasm-bindgen/pull/4318) -* Add clear error message to communicate new feature resolver version requirements. - [#4312](https://github.com/rustwasm/wasm-bindgen/pull/4312) +* Add `WASM_BINDGEN_TEST_DRIVER_TIMEOUT` environment variable to control the timeout to start and connect to the test driver. + [#4320](https://github.com/rustwasm/wasm-bindgen/pull/4320) + +### Changed * Remove `once_cell/critical-section` requirement for `no_std` with atomics. [#4322](https://github.com/rustwasm/wasm-bindgen/pull/4322) -### Changed - * `static FOO: Option` now returns `None` if undeclared in JS instead of throwing an error in JS. [#4319](https://github.com/rustwasm/wasm-bindgen/pull/4319) diff --git a/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs b/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs index e1c20ec6229..9ec6fabe2e9 100644 --- a/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs +++ b/crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs @@ -55,7 +55,12 @@ pub struct LegacyNewSessionParameters { /// binary, controlling it, running tests, scraping output, displaying output, /// etc. It will return `Ok` if all tests finish successfully, and otherwise it /// will return an error if some tests failed. -pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error> { +pub fn run( + server: &SocketAddr, + shell: &Shell, + driver_timeout: u64, + test_timeout: u64, +) -> Result<(), Error> { let driver = Driver::find()?; let mut drop_log: Box = Box::new(|| ()); let driver_url = match driver.location() { @@ -64,7 +69,7 @@ pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error // Wait for the driver to come online and bind its port before we try to // connect to it. let start = Instant::now(); - let max = Duration::new(5, 0); + let max = Duration::new(driver_timeout, 0); let (driver_addr, mut child) = 'outer: loop { // Allow tests to run in parallel (in theory) by finding any open port @@ -173,7 +178,7 @@ pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error // information. shell.status("Waiting for test to finish..."); let start = Instant::now(); - let max = Duration::new(timeout, 0); + let max = Duration::new(test_timeout, 0); while start.elapsed() < max { if client.text(&id, &output)?.contains("test result: ") { break; diff --git a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs index 93cead3c2cd..76259378054 100644 --- a/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs +++ b/crates/cli/src/bin/wasm-bindgen-test-runner/main.rs @@ -214,7 +214,15 @@ fn main() -> anyhow::Result<()> { return Ok(()); } - let timeout = env::var("WASM_BINDGEN_TEST_TIMEOUT") + let driver_timeout = env::var("WASM_BINDGEN_TEST_DRIVER_TIMEOUT") + .map(|timeout| { + timeout + .parse() + .expect("Could not parse 'WASM_BINDGEN_TEST_DRIVER_TIMEOUT'") + }) + .unwrap_or(5); + + let browser_timeout = env::var("WASM_BINDGEN_TEST_TIMEOUT") .map(|timeout| { timeout .parse() @@ -223,7 +231,7 @@ fn main() -> anyhow::Result<()> { .unwrap_or(20); if debug { - println!("Set timeout to {} seconds...", timeout); + println!("Set timeout to {} seconds...", browser_timeout); } // Make the generated bindings available for the tests to execute against. @@ -307,7 +315,7 @@ fn main() -> anyhow::Result<()> { } thread::spawn(|| srv.run()); - headless::run(&addr, &shell, timeout)?; + headless::run(&addr, &shell, driver_timeout, browser_timeout)?; } } Ok(())