Skip to content

Commit

Permalink
chore(tests): maybe fix flaky flock tests (denoland#12122)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Sep 17, 2021
1 parent 4c8ab33 commit 7c0173d
Showing 1 changed file with 5 additions and 8 deletions.
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

0 comments on commit 7c0173d

Please sign in to comment.