denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.27k stars 5.41k forks source link

Test runner does not wait for web worker to terminate #21007

Open scarf005 opened 1 year ago

scarf005 commented 1 year ago

Summary

test runners do not wait for web workers to terminate.

Minimal reproduction

// a.ts
setTimeout(() => console.log("hello"), 1000)
// a_test.ts
const foo = () => {
    const worker = new Worker(new URL("./a.ts", import.meta.url), { type: "module" })

    return new Promise(() => worker.terminate())
}

Deno.test("wait for worker", async () => {
    console.log("begin")
    await foo()
    console.log("end")
})

Actual behavior

running 1 test from ./a_test.ts
wait for worser ...
------- output -------
begin
Check file:///home/scarf/repo/w1-social-feed/a.ts

ok | 0 passed | 0 failed (110ms)

error: Promise resolution is still pending but the event loop has already resolved.

System Info

deno 1.37.2+8f065a6 (canary, x86_64-unknown-linux-gnu)
v8 11.8.172.13
typescript 5.2.2
Ubuntu 23.04
loynoir commented 8 months ago

Hello @scarf005, FYI, workaround exists, don't await p, but await pWrapper(p, timeout)