Skip to content
Myr

Fix flaky totalTimeout retry test

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sindre Sorhus · committed by Sindre Sorhus · parent b101251 · Browse files · 1 file+10 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−7 removed

  • tests:+10 added−7 removed

1 file+10 added−7 removed

modified:test/retry.ts+10 added-7 removed
1992 unmodified lines
1993 let requestCount = 0;19941995 const customFetch: typeof fetch = async () => {1996 requestCount++;1997 // Each attempt takes 600ms, exceeding the 400ms per-attempt timeout1998 await delay(600);1997 // Each attempt takes longer than the per-attempt timeout, so every attempt times out.1998 await delay(300);1999 return new Response('ok');2000 };20012002 await t.throwsAsync(2003 ky('https://example.com', {2004 fetch: customFetch,2005 timeout: 400,2006 totalTimeout: 1500,2005 timeout: 100,2006 totalTimeout: 1000,2007 retry: {2008 limit: 10,2008 limit: 30,2009 retryOnTimeout: true,2010 delay: () => 0,2011 },2012 }).text(),
1 unmodified line
2014 name: 'TimeoutError',2015 },2016 );20172018 // Each attempt times out at ~400ms. Within 1500ms totalTimeout, 2-4 attempts fit.2019 t.true(requestCount >= 2 && requestCount <= 4);2018 // Each attempt times out at ~100ms, so many attempts fit within the 1000ms totalTimeout.2019 // The exact count is timing-dependent (slow CI runs fewer), so we only assert the invariant:2020 // it retried at least once, and totalTimeout stopped it well before the retry limit.2021 t.true(requestCount >= 2, `Expected at least 2 attempts, got ${requestCount}`);2022 t.true(requestCount < 30, `Expected totalTimeout to cap below the retry limit, got ${requestCount}`);2023});20242025test('NetworkError wraps fetch network errors', async t => {2026 const error = await t.throwsAsync(
240 unmodified lines