diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-03-07 18:51:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 18:51:19 -0700 |
commit | 3745556ccdaa14ac7a9e0849b743669aee124cb3 (patch) | |
tree | c97367a326a6de72ada2dc20fe72c2e3b7629b75 /tests | |
parent | 2dfc0aca7c6a04d54fe6f9a73be70fc4c591d552 (diff) |
feat(ext/node): ref/unref on workers (#22778)
Implements ref/unref on worker to fix part of #22629
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_node/worker_threads_test.ts | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/unit_node/worker_threads_test.ts b/tests/unit_node/worker_threads_test.ts index 5d3023069..bc451e33f 100644 --- a/tests/unit_node/worker_threads_test.ts +++ b/tests/unit_node/worker_threads_test.ts @@ -1,6 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertObjectMatch } from "@std/assert/mod.ts"; +import { + assert, + assertEquals, + assertObjectMatch, + fail, +} from "@std/assert/mod.ts"; import { fromFileUrl, relative } from "@std/path/mod.ts"; import * as workerThreads from "node:worker_threads"; import { EventEmitter, once } from "node:events"; @@ -198,3 +203,18 @@ Deno.test({ worker.terminate(); }, }); + +Deno.test({ + name: "[worker_threads] unref", + async fn() { + const timeout = setTimeout(() => fail("Test timed out"), 60_000); + const child = new Deno.Command(Deno.execPath(), { + args: [ + "eval", + "import { Worker } from 'node:worker_threads'; new Worker('setTimeout(() => {}, 1_000_000)', {eval:true}).unref();", + ], + }).spawn(); + await child.status; + clearTimeout(timeout); + }, +}); |