diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-07-07 16:28:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-07 16:28:29 +0200 |
commit | 870eb0df81d35b6543b602151e4f36b4eb1aeece (patch) | |
tree | fa59d74eee8198c93d329b45241e74f4f43b2a5d | |
parent | 82f7daeed77f0250f154d83571f54382a51b1c77 (diff) |
fix(core): deflake WASM termination test (#15103)
-rw-r--r-- | core/runtime.rs | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/core/runtime.rs b/core/runtime.rs index 4fea4156d..daefe4121 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -2307,23 +2307,13 @@ pub mod tests { #[test] fn terminate_execution_webassembly() { - let (mut isolate, _dispatch_count) = setup(Mode::Async); - let v8_isolate_handle = isolate.v8_isolate().thread_safe_handle(); - - let terminator_thread = std::thread::spawn(move || { - // allow deno to boot and run - std::thread::sleep(std::time::Duration::from_millis(1000)); - - // terminate execution - let ok = v8_isolate_handle.terminate_execution(); - assert!(ok); - }); + let (mut runtime, _dispatch_count) = setup(Mode::Async); + let v8_isolate_handle = runtime.v8_isolate().thread_safe_handle(); // Run an infinite loop in Webassemby code, which should be terminated. - isolate.execute_script("infinite_wasm_loop.js", + let promise = runtime.execute_script("infinite_wasm_loop.js", r#" (async () => { - console.log("Begin"); const wasmCode = new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 7, 17, 1, 13, @@ -2332,23 +2322,31 @@ pub mod tests { 12, 0, 11, 11, ]); const wasmModule = await WebAssembly.compile(wasmCode); - const wasmInstance = new WebAssembly.Instance(wasmModule); - wasmInstance.exports.infinite_loop(); - })(); - "#).expect("wasm infinite loop failed"); - match futures::executor::block_on(isolate.run_event_loop(false)) { - Ok(_) => panic!("execution should be terminated"), - Err(e) => { - assert_eq!(e.to_string(), "Uncaught Error: execution terminated") - } - } + globalThis.wasmInstance = new WebAssembly.Instance(wasmModule); + })() + "#).unwrap(); + futures::executor::block_on(runtime.resolve_value(promise)).unwrap(); + let terminator_thread = std::thread::spawn(move || { + std::thread::sleep(std::time::Duration::from_millis(1000)); + + // terminate execution + let ok = v8_isolate_handle.terminate_execution(); + assert!(ok); + }); + let err = runtime + .execute_script( + "infinite_wasm_loop2.js", + "globalThis.wasmInstance.exports.infinite_loop();", + ) + .unwrap_err(); + assert_eq!(err.to_string(), "Uncaught Error: execution terminated"); // Cancel the execution-terminating exception in order to allow script // execution again. - let ok = isolate.v8_isolate().cancel_terminate_execution(); + let ok = runtime.v8_isolate().cancel_terminate_execution(); assert!(ok); // Verify that the isolate usable again. - isolate + runtime .execute_script("simple.js", "1 + 1") .expect("execution should be possible again"); |