From fc71b5c8077fb011e262dcd7f7428c350189c7fd Mon Sep 17 00:00:00 2001 From: Patrick Mueller Date: Tue, 21 Jan 2020 14:55:21 -0500 Subject: [PATCH] fix flaky test with delay --- x-pack/plugins/event_log/server/lib/delay.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/event_log/server/lib/delay.test.ts b/x-pack/plugins/event_log/server/lib/delay.test.ts index a11bae0a5c7e1..22355ebec505d 100644 --- a/x-pack/plugins/event_log/server/lib/delay.test.ts +++ b/x-pack/plugins/event_log/server/lib/delay.test.ts @@ -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); }); });