From cdc103faf97a6f3de16730e5b857a77775d609ad Mon Sep 17 00:00:00 2001 From: Michael Piazza Date: Thu, 22 Dec 2022 11:16:20 -0800 Subject: [PATCH] [PAY-123] Fix flaky rewards test (#4528) --- libs/tests/rewardsAttesterTest.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libs/tests/rewardsAttesterTest.js b/libs/tests/rewardsAttesterTest.js index 5932b494d8f..2b9da954160 100644 --- a/libs/tests/rewardsAttesterTest.js +++ b/libs/tests/rewardsAttesterTest.js @@ -120,10 +120,12 @@ describe('Delay calculator tests', () => { const solSlot = { last: 100 } - // new slots every 250ms + // new slots every ~250ms for 4 slots/sec + // give it a little padding to make sure we produce + // a slot before the pollingInterval runs const i = setInterval(() => { solSlot.last += 1 - }, 250) + }, 230) const libs = new MockLibs( () => solSlot.last, @@ -138,13 +140,15 @@ describe('Delay calculator tests', () => { }) calc.start() const slotThreshold1 = await calc.getSolanaSlotThreshold() - // Initially this should be 0.5sec/slot + // Initially this rate should be 0.5sec/slot + // 100 starting - 1s * 2slot/sec assert.strictEqual(slotThreshold1, 90) - // Wait for staleness interval + // Wait for staleness interval of 1s await new Promise((res) => setTimeout(res, 1100)) const slotThreshold2 = await calc.getSolanaSlotThreshold() - // Current slot should be 104, and there should be 4 slots/sec, + // Current slot should be 104 + // it should calculate 4 slot/sec // so 5 sec lag behind = 104 - 5 * 4 = 84 assert.strictEqual(slotThreshold2, 84)