mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
chore: make commandWithCwdIsAsync test less flaky (#26770)
This commit is contained in:
parent
b9262130fe
commit
bf82c6697a
1 changed files with 14 additions and 4 deletions
|
@ -14,27 +14,31 @@ Deno.test(
|
||||||
const enc = new TextEncoder();
|
const enc = new TextEncoder();
|
||||||
const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" });
|
const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" });
|
||||||
|
|
||||||
|
const exitCodeFileLock = "deno_was_here.lock";
|
||||||
const exitCodeFile = "deno_was_here";
|
const exitCodeFile = "deno_was_here";
|
||||||
const programFile = "poll_exit.ts";
|
const programFile = "poll_exit.ts";
|
||||||
const program = `
|
const program = `
|
||||||
|
const file = await Deno.open("${exitCodeFileLock}", { write: true, create: true });
|
||||||
async function tryExit() {
|
async function tryExit() {
|
||||||
|
await file.lock(true);
|
||||||
try {
|
try {
|
||||||
const code = parseInt(await Deno.readTextFile("${exitCodeFile}"));
|
const code = parseInt(await Deno.readTextFile("${exitCodeFile}"));
|
||||||
Deno.exit(code);
|
Deno.exit(code);
|
||||||
} catch {
|
} catch {
|
||||||
// Retry if we got here before deno wrote the file.
|
// Retry if we got here before deno wrote the file.
|
||||||
setTimeout(tryExit, 0.01);
|
setTimeout(tryExit, 0.01);
|
||||||
|
} finally {
|
||||||
|
await file.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tryExit();
|
tryExit();
|
||||||
`;
|
`;
|
||||||
|
|
||||||
Deno.writeFileSync(`${cwd}/${programFile}`, enc.encode(program));
|
Deno.writeFileSync(`${cwd}/${programFile}`, enc.encode(program));
|
||||||
|
|
||||||
const command = new Deno.Command(Deno.execPath(), {
|
const command = new Deno.Command(Deno.execPath(), {
|
||||||
cwd,
|
cwd,
|
||||||
args: ["run", "--allow-read", programFile],
|
args: ["run", "-RW", programFile],
|
||||||
stdout: "inherit",
|
stdout: "inherit",
|
||||||
stderr: "inherit",
|
stderr: "inherit",
|
||||||
});
|
});
|
||||||
|
@ -43,12 +47,18 @@ tryExit();
|
||||||
// Write the expected exit code *after* starting deno.
|
// Write the expected exit code *after* starting deno.
|
||||||
// This is how we verify that `Child` is actually asynchronous.
|
// This is how we verify that `Child` is actually asynchronous.
|
||||||
const code = 84;
|
const code = 84;
|
||||||
Deno.writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`));
|
|
||||||
|
|
||||||
|
await using file = await Deno.open(`${cwd}/${exitCodeFileLock}`, {
|
||||||
|
write: true,
|
||||||
|
create: true,
|
||||||
|
});
|
||||||
|
await file.lock(true);
|
||||||
|
Deno.writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`));
|
||||||
|
await file.unlock();
|
||||||
const status = await child.status;
|
const status = await child.status;
|
||||||
await Deno.remove(cwd, { recursive: true });
|
await Deno.remove(cwd, { recursive: true });
|
||||||
assertEquals(status.success, false);
|
|
||||||
assertEquals(status.code, code);
|
assertEquals(status.code, code);
|
||||||
|
assertEquals(status.success, false);
|
||||||
assertEquals(status.signal, null);
|
assertEquals(status.signal, null);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue