Skip to content

Commit

Permalink
Assert error messages in retry tests (#229)
Browse files Browse the repository at this point in the history
* tests: check all retry failure for correct status text

* Fix code style issues

Co-authored-by: Seth Holladay <me@seth-holladay.com>
  • Loading branch information
elijahsmith and sholladay committed Jan 30, 2020
1 parent bb46ca8 commit 78814e7
Showing 1 changed file with 94 additions and 61 deletions.
155 changes: 94 additions & 61 deletions test/retry.js
Expand Up @@ -156,11 +156,14 @@ test('respect number of retries', async t => {
response.sendStatus(408);
});

await t.throwsAsync(ky(server.url, {
retry: {
limit: 3
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 3
}
}).text(),
/Request Timeout/
);
t.is(requestCount, 3);

await server.close();
Expand All @@ -180,22 +183,28 @@ test('respect retry methods', async t => {
response.sendStatus(408);
});

await t.throwsAsync(ky(server.url, {
method: 'post',
retry: {
limit: 3,
methods: ['get']
}
}).text());
await t.throwsAsync(
ky(server.url, {
method: 'post',
retry: {
limit: 3,
methods: ['get']
}
}).text(),
/Request Timeout/
);
t.is(requestCount, 1);

requestCount = 0;
await t.throwsAsync(ky(server.url, {
retry: {
limit: 3,
methods: ['get']
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 3,
methods: ['get']
}
}).text(),
/Request Timeout/
);
t.is(requestCount, 3);

await server.close();
Expand All @@ -215,21 +224,27 @@ test('respect maxRetryAfter', async t => {
response.end('');
});

await t.throwsAsync(ky(server.url, {
retry: {
limit: 5,
maxRetryAfter: 100
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 5,
maxRetryAfter: 100
}
}).text(),
/Payload Too Large/
);
t.is(requestCount, 1);

requestCount = 0;
await t.throwsAsync(ky(server.url, {
retry: {
limit: 5,
maxRetryAfter: 2000
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 5,
maxRetryAfter: 2000
}
}).text(),
/Payload Too Large/
);
t.is(requestCount, 5);

await server.close();
Expand All @@ -244,7 +259,10 @@ test('retry - can provide retry as number', async t => {
response.sendStatus(408);
});

await t.throwsAsync(ky(server.url, {retry: 5}).text());
await t.throwsAsync(
ky(server.url, {retry: 5}).text(),
/Request Timeout/
);
t.is(requestCount, 5);

await server.close();
Expand All @@ -260,13 +278,16 @@ test('doesn\'t retry on 413 with empty statusCodes and methods', async t => {
response.sendStatus(413);
});

await t.throwsAsync(ky(server.url, {
retry: {
limit: 10,
statusCodes: [],
methods: []
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 10,
statusCodes: [],
methods: []
}
}).text(),
/Payload Too Large/
);

t.is(requestCount, 1);

Expand All @@ -282,12 +303,15 @@ test('doesn\'t retry on 413 with empty methods', async t => {
response.sendStatus(413);
});

await t.throwsAsync(ky(server.url, {
retry: {
limit: 10,
methods: []
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 10,
methods: []
}
}).text(),
/Payload Too Large/
);

t.is(requestCount, 1);

Expand All @@ -303,12 +327,15 @@ test('does retry on 408 with methods provided as array', async t => {
response.sendStatus(408);
});

await t.throwsAsync(ky(server.url, {
retry: {
limit: 4,
methods: ['get']
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 4,
methods: ['get']
}
}).text(),
/Request Timeout/
);

t.is(requestCount, 4);

Expand All @@ -324,12 +351,15 @@ test('does retry on 408 with statusCodes provided as array', async t => {
response.sendStatus(408);
});

await t.throwsAsync(ky(server.url, {
retry: {
limit: 4,
statusCodes: [408]
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 4,
statusCodes: [408]
}
}).text(),
/Request Timeout/
);

t.is(requestCount, 4);

Expand All @@ -345,11 +375,14 @@ test('doesn\'t retry when retry.limit is set to 0', async t => {
response.sendStatus(408);
});

await t.throwsAsync(ky(server.url, {
retry: {
limit: 0
}
}).text());
await t.throwsAsync(
ky(server.url, {
retry: {
limit: 0
}
}).text(),
/Request Timeout/
);

t.is(requestCount, 1);

Expand Down

0 comments on commit 78814e7

Please sign in to comment.