Skip to content

Commit

Permalink
fix flaky test with delay
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed Jan 21, 2020
1 parent d6cab0d commit fc71b5c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions x-pack/plugins/event_log/server/lib/delay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

import { delay } from './delay';

const TEST_DELAY = 100;

describe('delay', () => {
test('works as expected', async () => {
const timeStart = Date.now();
await delay(100);
expect(Date.now() - timeStart).toBeGreaterThanOrEqual(100);
await delay(TEST_DELAY);

// note: testing with .toBeGreaterThanOrEqual(TEST_DELAY) is flaky,
// sometimes the actual value is TEST_DELAY - 1, so ... using that as the
// value to test against; something funky with time rounding I'd guess.
expect(Date.now() - timeStart).toBeGreaterThanOrEqual(TEST_DELAY - 1);
});
});

0 comments on commit fc71b5c

Please sign in to comment.