Allow changing the wasm-bindgen-test-runner timeout via an env variable (#2036)

* Add WASM_BINDGEN_TEST_TIMEOUT

* Formatting
This commit is contained in:
Ashley 2020-03-10 16:36:00 +01:00 committed by GitHub
parent 035902ab51
commit 8a3bdbd8ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -55,7 +55,7 @@ pub struct LegacyNewSessionParameters {
/// binary, controlling it, running tests, scraping output, displaying output, /// binary, controlling it, running tests, scraping output, displaying output,
/// etc. It will return `Ok` if all tests finish successfully, and otherwise it /// etc. It will return `Ok` if all tests finish successfully, and otherwise it
/// will return an error if some tests failed. /// 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 driver = Driver::find()?;
let mut drop_log: Box<dyn FnMut()> = Box::new(|| ()); let mut drop_log: Box<dyn FnMut()> = Box::new(|| ());
let driver_url = match driver.location() { let driver_url = match driver.location() {
@ -145,7 +145,7 @@ pub fn run(server: &SocketAddr, shell: &Shell) -> Result<(), Error> {
// information. // information.
shell.status("Waiting for test to finish..."); shell.status("Waiting for test to finish...");
let start = Instant::now(); let start = Instant::now();
let max = Duration::new(20, 0); let max = Duration::new(timeout, 0);
while start.elapsed() < max { while start.elapsed() < max {
if client.text(&id, &output)?.contains("test result: ") { if client.text(&id, &output)?.contains("test result: ") {
break; break;
@ -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. // output, so we shouldn't need the driver logs to get printed.
drop_log(); drop_log();
} else { } 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 { if output.len() > 0 {
println!("output div contained:\n{}", tab(&output)); println!("output div contained:\n{}", tab(&output));
} }

View File

@ -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. // Make the generated bindings available for the tests to execute against.
shell.status("Executing bindgen..."); shell.status("Executing bindgen...");
let mut b = Bindgen::new(); let mut b = Bindgen::new();
@ -167,6 +179,6 @@ integration test.\
} }
thread::spawn(|| srv.run()); thread::spawn(|| srv.run());
headless::run(&addr, &shell)?; headless::run(&addr, &shell, timeout)?;
Ok(()) Ok(())
} }