Skip to content

Commit 9b13d1e

Browse files
committed
Fix additional flaky tests
1 parent 9eb3f67 commit 9b13d1e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/iterable-queue-mapper.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ describe('IterableQueueMapper', () => {
8989
expect(loopCount).toBe(max);
9090
expect(lastTotal).toBe(max);
9191
// Should require at least 4 batches
92+
const duration = Date.now() - startTime;
9293
expect(Date.now() - startTime).toBeLessThan(5 * delayBetweenMs);
93-
expect(Date.now() - startTime).toBeGreaterThan(4 * delayBetweenMs);
94+
expect(Math.ceil(duration)).toBeGreaterThan(4 * delayBetweenMs);
9495
});
9596

9697
it('right number run in parallel - complex', async () => {
@@ -108,7 +109,7 @@ describe('IterableQueueMapper', () => {
108109
// Next one added should have had to wait for at least one wait period
109110
void (async () => {
110111
await prefetcher.enqueue({ value: 5, ms: delayBetweenMs });
111-
expect(Date.now() - startTime).toBeGreaterThanOrEqual(delayBetweenMs);
112+
expect(Math.ceil(Date.now() - startTime)).toBeGreaterThanOrEqual(delayBetweenMs);
112113
prefetcher.done();
113114
})();
114115

@@ -125,8 +126,9 @@ describe('IterableQueueMapper', () => {
125126
expect(lastSeen).toBe(5);
126127

127128
// Should require at least 2 batches
128-
expect(Date.now() - startTime).toBeLessThan(2.5 * delayBetweenMs);
129-
expect(Date.now() - startTime).toBeGreaterThan(2 * delayBetweenMs);
129+
const duration = Date.now() - startTime;
130+
expect(duration).toBeLessThan(2.5 * delayBetweenMs);
131+
expect(Math.ceil(duration)).toBeGreaterThan(2 * delayBetweenMs);
130132
});
131133
});
132134
});

0 commit comments

Comments
 (0)