Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(retry): allow respecting Retry-After for user-defined status codes #598

Prev Previous commit
Next Next commit
chore: add missing assertions for requestCount
Made sure they were defined parametrically, where appropriate.
Magic values on a per-test basis were left untouched.
  • Loading branch information
Kenneth-Sills committed Jul 3, 2024
commit 9bb26586c0214f401ba7fabe354fc9069ed2aaf9
10 changes: 8 additions & 2 deletions test/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test('network error', async t => {
});

t.is(await ky(server.url).text(), fixture);
t.is(requestCount, defaultRetryCount + 1);

await server.close();
});
Expand All @@ -44,6 +45,7 @@ test('status code 500', async t => {
});

t.is(await ky(server.url).text(), fixture);
t.is(requestCount, defaultRetryCount + 1);

await server.close();
});
Expand All @@ -63,6 +65,7 @@ test('only on defined status codes', async t => {
});

await t.throwsAsync(ky(server.url).text(), {message: /Bad Request/});
t.is(requestCount, 1);

await server.close();
});
Expand All @@ -84,6 +87,7 @@ test('not on POST', async t => {
await t.throwsAsync(ky.post(server.url).text(), {
message: /Internal Server Error/,
});
t.is(requestCount, 1);

await server.close();
});
Expand Down Expand Up @@ -141,6 +145,7 @@ test('respect 413 Retry-After', async t => {

const result = await ky(server.url).text();
t.true(Number(result) >= retryAfterOn413 * 1000);
t.is(requestCount, retryAfterOn413 + 1);

await server.close();
});
Expand All @@ -165,7 +170,7 @@ test('respect 413 Retry-After with timestamp', async t => {

const result = await ky(server.url).text();
t.true(Number(result) >= retryAfterOn413 * 1000);
t.is(requestCount, 3);
t.is(requestCount, retryAfterOn413 + 1);

await server.close();
});
Expand Down Expand Up @@ -206,6 +211,7 @@ test('respect custom `afterStatusCodes` (500) with Retry-After header', async t

const result = await ky(server.url, {retry: {afterStatusCodes: [500]}}).text();
t.true(Number(result) >= retryAfterOn500 * 1000);
t.is(requestCount, retryAfterOn500 + 1);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing an assertion for the requestCount.

Looks like some of the other retry tests also have this mistake.

await server.close();
});
Expand Down Expand Up @@ -274,7 +280,7 @@ test('respect retry methods', async t => {
message: /Request Timeout/,
},
);
t.is(requestCount, 3);
t.is(requestCount, defaultRetryCount + 1);

await server.close();
});
Expand Down