Skip to content

Commit 397b36f

Browse files
committed
(#109) Restructured sleep tests to use deltas
1 parent fb1f36b commit 397b36f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/sleep.function.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ describe("sleep", () => {
1111
const before = Date.now();
1212
await sleep(timeout);
1313
const after = Date.now();
14-
const delta = Math.abs((after - before) - timeout);
1514

1615
// THEN
17-
expect(delta).toBeLessThanOrEqual(maxTimeDeltaInMs);
16+
expect(after - before).toBeGreaterThanOrEqual(timeout - maxTimeDeltaInMs);
1817
});
1918
});
2019

@@ -28,9 +27,8 @@ describe("busyWaitForNanoSeconds", () => {
2827
const before = Date.now();
2928
await busyWaitForNanoSeconds(timeoutNs);
3029
const after = Date.now();
31-
const delta = Math.abs((after - before) - timeoutMs);
3230

3331
// THEN
34-
expect(delta).toBeLessThanOrEqual(maxTimeDeltaInMs);
32+
expect(after - before).toBeGreaterThanOrEqual(timeoutMs - maxTimeDeltaInMs);
3533
});
3634
});

0 commit comments

Comments
 (0)