Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node/child_process): Try to fix flaky tests #876

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 64 additions & 48 deletions node/child_process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,26 @@ Deno.test("[child_process spawn] 'spawn' event", async () => {
Deno.test("[child_process spawn] Verify that a shell is executed", async () => {
const promise = withTimeout(3000);
const doesNotExist = spawn("does-not-exist", { shell: true });
assertNotStrictEquals(doesNotExist.spawnfile, "does-not-exist");
doesNotExist.on("error", () => {
promise.reject("The 'error' event must not be emitted.");
});
doesNotExist.on("exit", (code, signal) => {
assertStrictEquals(signal, null);
try {
assertNotStrictEquals(doesNotExist.spawnfile, "does-not-exist");
doesNotExist.on("error", () => {
promise.reject("The 'error' event must not be emitted.");
});
doesNotExist.on("exit", (code, signal) => {
assertStrictEquals(signal, null);

if (isWindows) {
assertStrictEquals(code, 1); // Exit code of cmd.exe
} else {
assertStrictEquals(code, 127); // Exit code of /bin/sh });
}
if (isWindows) {
assertStrictEquals(code, 1); // Exit code of cmd.exe
} else {
assertStrictEquals(code, 127); // Exit code of /bin/sh });
}

promise.resolve();
});
await promise;
promise.resolve();
});
await promise;
} finally {
doesNotExist.kill();
}
});

// TODO(uki00a): Remove this case once Node's `parallel/test-child-process-spawn-shell.js` works.
Expand All @@ -163,19 +167,23 @@ Deno.test({
});
let echoOutput = "";

assertStrictEquals(
echo.spawnargs[echo.spawnargs.length - 1].replace(/"/g, ""),
"echo foo",
);
assert(echo.stdout);
echo.stdout.on("data", (data) => {
echoOutput += data;
});
echo.on("close", () => {
assertStrictEquals(echoOutput.trim(), "foo");
promise.resolve();
});
await promise;
try {
assertStrictEquals(
echo.spawnargs[echo.spawnargs.length - 1].replace(/"/g, ""),
"echo foo",
);
assert(echo.stdout);
echo.stdout.on("data", (data) => {
echoOutput += data;
});
echo.on("close", () => {
assertStrictEquals(echoOutput.trim(), "foo");
promise.resolve();
});
await promise;
} finally {
echo.kill();
}
},
});

Expand All @@ -189,19 +197,23 @@ Deno.test({
const command = spawn(cmd, {
shell: true,
});
let commandOutput = "";
try {
let commandOutput = "";

assert(command.stdout);
command.stdout.on("data", (data) => {
commandOutput += data;
});
assert(command.stdout);
command.stdout.on("data", (data) => {
commandOutput += data;
});

command.on("close", () => {
assertStrictEquals(commandOutput.trim(), "bar");
promise.resolve();
});
command.on("close", () => {
assertStrictEquals(commandOutput.trim(), "bar");
promise.resolve();
});

await promise;
await promise;
} finally {
command.kill();
}
},
});

Expand All @@ -219,18 +231,22 @@ Deno.test({
shell: true,
},
);
let envOutput = "";
try {
let envOutput = "";

assert(env.stdout);
env.on("error", (err) => promise.reject(err));
env.stdout.on("data", (data) => {
envOutput += data;
});
env.on("close", () => {
assertStrictEquals(envOutput.trim(), "buzz");
promise.resolve();
});
await promise;
assert(env.stdout);
env.on("error", (err) => promise.reject(err));
env.stdout.on("data", (data) => {
envOutput += data;
});
env.on("close", () => {
assertStrictEquals(envOutput.trim(), "buzz");
promise.resolve();
});
await promise;
} finally {
env.kill();
}
},
});
/* End of ported part */