diff options
Diffstat (limited to 'cli/tests/unit/spawn_test.ts')
-rw-r--r-- | cli/tests/unit/spawn_test.ts | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/cli/tests/unit/spawn_test.ts b/cli/tests/unit/spawn_test.ts index 42df23b1f..51664e3d1 100644 --- a/cli/tests/unit/spawn_test.ts +++ b/cli/tests/unit/spawn_test.ts @@ -723,8 +723,29 @@ Deno.test( const program = ` const child = await Deno.spawnChild(Deno.execPath(), { cwd: Deno.args[0], + stdout: "piped", args: ["run", "-A", "--unstable", Deno.args[1]], }); +const readable = child.stdout.pipeThrough(new TextDecoderStream()); +const reader = readable.getReader(); +// set up an interval that will end after reading a few messages from stdout, +// to verify that stdio streams are properly unrefed +let count = 0; +let interval; +interval = setInterval(async () => { + count += 1; + if (count > 10) { + clearInterval(interval); + console.log("cleared interval"); + } + const res = await reader.read(); + if (res.done) { + throw new Error("stream shouldn't be done"); + } + if (res.value.trim() != "hello from interval") { + throw new Error("invalid message received"); + } +}, 120); console.log("spawned pid", child.pid); child.unref(); `; @@ -740,15 +761,19 @@ setInterval(() => { // In this subprocess we are spawning another subprocess which has // an infite interval set. Following call would never resolve unless // child process gets unrefed. - const { success, stdout } = await Deno.spawn(Deno.execPath(), { + const { success, stdout, stderr } = await Deno.spawn(Deno.execPath(), { cwd, args: ["run", "-A", "--unstable", programFile, cwd, childProgramFile], }); assert(success); const stdoutText = new TextDecoder().decode(stdout); - const pidStr = stdoutText.split(" ").at(-1); + const stderrText = new TextDecoder().decode(stderr); + assert(stderrText.length == 0); + const [line1, line2] = stdoutText.split("\n"); + const pidStr = line1.split(" ").at(-1); assert(pidStr); + assertEquals(line2, "cleared interval"); const pid = Number.parseInt(pidStr, 10); await Deno.remove(cwd, { recursive: true }); // Child process should have been killed when parent process exits. |