Skip to content

Commit

Permalink
Allow changing the wasm-bindgen-test-runner timeout via an env vari…
Browse files Browse the repository at this point in the history
…able (#2036)

* Add WASM_BINDGEN_TEST_TIMEOUT

* Formatting
  • Loading branch information
expenses authored Mar 10, 2020
1 parent 035902a commit 8a3bdbd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions crates/cli/src/bin/wasm-bindgen-test-runner/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ 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) -> Result<(), Error> {
pub fn run(server: &SocketAddr, shell: &Shell, timeout: u64) -> Result<(), Error> {
let driver = Driver::find()?;
let mut drop_log: Box<dyn FnMut()> = Box::new(|| ());
let driver_url = match driver.location() {
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
// information.
shell.status("Waiting for test to finish...");
let start = Instant::now();
let max = Duration::new(20, 0);
let max = Duration::new(timeout, 0);
while start.elapsed() < max {
if client.text(&id, &output)?.contains("test result: ") {
break;
Expand All @@ -170,7 +170,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
// output, so we shouldn't need the driver logs to get printed.
drop_log();
} else {
println!("failed to detect test as having been run");
println!("Failed to detect test as having been run. It might have timed out.");
if output.len() > 0 {
println!("output div contained:\n{}", tab(&output));
}
Expand Down
14 changes: 13 additions & 1 deletion crates/cli/src/bin/wasm-bindgen-test-runner/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ integration test.\
}
}

let timeout = env::var("WASM_BINDGEN_TEST_TIMEOUT")
.map(|timeout| {
timeout
.parse()
.expect("Could not parse 'WASM_BINDGEN_TEST_TIMEOUT'")
})
.unwrap_or(20);

if debug {
println!("Set timeout to {} seconds...", timeout);
}

// Make the generated bindings available for the tests to execute against.
shell.status("Executing bindgen...");
let mut b = Bindgen::new();
Expand Down Expand Up @@ -167,6 +179,6 @@ integration test.\
}

thread::spawn(|| srv.run());
headless::run(&addr, &shell)?;
headless::run(&addr, &shell, timeout)?;
Ok(())
}

0 comments on commit 8a3bdbd

Please sign in to comment.