Skip to content

Commit 2afa1a9

Browse files
committed
Add WASM_BINDGEN_DRIVER_TIMEOUT
The timeout to connect to the test driver in `wasm-bindgen-test-runner` can now be configured via `WASM_BINDGEN_DRIVER_TIMEOUT`. This is useful when testing on a slower machine, e.g. CI.
1 parent 3a8da7c commit 2afa1a9

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# `wasm-bindgen` Change Log
22
--------------------------------------------------------------------------------
33

4+
## Unreleased
5+
6+
### Added
7+
8+
* The timeout to connect to the test driver in `wasm-bindgen-test-runner` can now be configured via `WASM_BINDGEN_DRIVER_TIMEOUT`. This is useful when testing on a slower machine, e.g. CI.
9+
[#2036](https://github.com/rustwasm/wasm-bindgen/pull/2036)
10+
11+
--------------------------------------------------------------------------------
12+
413
## [0.2.95](https://github.com/rustwasm/wasm-bindgen/compare/0.2.94...0.2.95)
514

615
Released 2024-10-10

crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ pub struct LegacyNewSessionParameters {
5555
/// binary, controlling it, running tests, scraping output, displaying output,
5656
/// etc. It will return `Ok` if all tests finish successfully, and otherwise it
5757
/// will return an error if some tests failed.
58-
pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error> {
58+
pub fn run(
59+
server: &SocketAddr,
60+
shell: &Shell,
61+
driver_timeout: u64,
62+
test_timeout: u64,
63+
) -> Result<(), Error> {
5964
let driver = Driver::find()?;
6065
let mut drop_log: Box<dyn FnMut()> = Box::new(|| ());
6166
let driver_url = match driver.location() {
@@ -79,7 +84,7 @@ pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error
7984
// Wait for the driver to come online and bind its port before we try to
8085
// connect to it.
8186
let start = Instant::now();
82-
let max = Duration::new(5, 0);
87+
let max = Duration::new(driver_timeout, 0);
8388
let mut bound = false;
8489
while start.elapsed() < max {
8590
if TcpStream::connect(driver_addr).is_ok() {
@@ -160,7 +165,7 @@ pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error
160165
// information.
161166
shell.status("Waiting for test to finish...");
162167
let start = Instant::now();
163-
let max = Duration::new(timeout, 0);
168+
let max = Duration::new(test_timeout, 0);
164169
while start.elapsed() < max {
165170
if client.text(&id, &output)?.contains("test result: ") {
166171
break;

crates/cli/src/bin/wasm-bindgen-test-runner/main.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn main() -> anyhow::Result<()> {
188188
return Ok(());
189189
}
190190

191-
let timeout = env::var("WASM_BINDGEN_TEST_TIMEOUT")
191+
let test_timeout = env::var("WASM_BINDGEN_TEST_TIMEOUT")
192192
.map(|timeout| {
193193
timeout
194194
.parse()
@@ -197,9 +197,17 @@ fn main() -> anyhow::Result<()> {
197197
.unwrap_or(20);
198198

199199
if debug {
200-
println!("Set timeout to {} seconds...", timeout);
200+
println!("Set timeout to {} seconds...", test_timeout);
201201
}
202202

203+
let driver_timeout = env::var("WASM_BINDGEN_DRIVER_TIMEOUT")
204+
.map(|timeout| {
205+
timeout
206+
.parse()
207+
.expect("Could not parse 'WASM_BINDGEN_DRIVER_TIMEOUT'")
208+
})
209+
.unwrap_or(5);
210+
203211
// Make the generated bindings available for the tests to execute against.
204212
shell.status("Executing bindgen...");
205213
let mut b = Bindgen::new();
@@ -281,7 +289,7 @@ fn main() -> anyhow::Result<()> {
281289
}
282290

283291
thread::spawn(|| srv.run());
284-
headless::run(&addr, &shell, timeout)?;
292+
headless::run(&addr, &shell, driver_timeout, test_timeout)?;
285293
}
286294
}
287295
Ok(())

0 commit comments

Comments
 (0)