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

chore(tests): maybe fix flaky flock tests #12122

Merged
merged 4 commits into from
Sep 17, 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
13 changes: 5 additions & 8 deletions cli/tests/unit/flock_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,17 @@ async function checkFirstBlocksSecond(opts: {
await firstProcess.signal();
await firstProcess.waitSignal(); // entering signal
await firstProcess.waitSignal(); // entered signal
await sleep(20);
// signal the second to enter the lock
await secondProcess.signal();
await secondProcess.waitSignal(); // entering signal
await sleep(20);
await sleep(100);
// signal to the first to exit the lock
await firstProcess.signal();
await sleep(20);
// collect the final output so we know it's exited the lock
const firstPsTimes = await firstProcess.getTimes();
// signal to the second to exit the lock
await secondProcess.waitSignal(); // entered signal
await secondProcess.signal();
// collect the remaining JSON output of both processes
const firstPsTimes = await firstProcess.getTimes();
const secondPsTimes = await secondProcess.getTimes();
return firstPsTimes.exitTime < secondPsTimes.enterTime;
} finally {
Expand Down Expand Up @@ -126,10 +124,9 @@ function runFlockTestProcess(opts: { exclusive: boolean; sync: boolean }) {

// record the exit time and wait a little bit before releasing
// the lock so that the enter time of the next process doesn't
// occur at the same time as this exit time (do double the
// windows clock resolution)
// occur at the same time as this exit time
const exitTime = new Date().getTime();
await new Promise((resolve) => setTimeout(resolve, 30));
Deno.sleepSync(100);

// release the lock
${opts.sync ? "Deno.funlockSync(rid);" : "await Deno.funlock(rid);"}
Expand Down