mirror of
https://github.com/actions/cache.git
synced 2025-04-21 11:36:45 +00:00
Use tries on all API calls
This commit is contained in:
parent
a8b61326cf
commit
c8d75a8073
4 changed files with 214 additions and 132 deletions
|
@ -59,20 +59,17 @@ function handleResponse(
|
|||
|
||||
async function testRetryExpectingResult(
|
||||
responses: Array<TestResponse>,
|
||||
expectedResult: string
|
||||
expectedResult: string | null
|
||||
): Promise<void> {
|
||||
responses = responses.reverse(); // Reverse responses since we pop from end
|
||||
|
||||
const actualResult = await retry(
|
||||
"test",
|
||||
() => handleResponse(responses.pop()),
|
||||
(response: TestResponse) => response.statusCode,
|
||||
(response: TestResponse) => response.result,
|
||||
(statusCode: number) => statusCode === 200,
|
||||
(statusCode: number) => statusCode === 503
|
||||
(response: TestResponse) => response.statusCode
|
||||
);
|
||||
|
||||
expect(actualResult).toEqual(expectedResult);
|
||||
expect(actualResult.result).toEqual(expectedResult);
|
||||
}
|
||||
|
||||
async function testRetryExpectingError(
|
||||
|
@ -84,10 +81,7 @@ async function testRetryExpectingError(
|
|||
retry(
|
||||
"test",
|
||||
() => handleResponse(responses.pop()),
|
||||
(response: TestResponse) => response.statusCode,
|
||||
(response: TestResponse) => response.result,
|
||||
(statusCode: number) => statusCode === 200,
|
||||
(statusCode: number) => statusCode === 503
|
||||
(response: TestResponse) => response.statusCode
|
||||
)
|
||||
).rejects.toBeInstanceOf(Error);
|
||||
}
|
||||
|
@ -165,3 +159,19 @@ test("retry works after error", async () => {
|
|||
"Ok"
|
||||
);
|
||||
});
|
||||
|
||||
test("retry returns after client error", async () => {
|
||||
await testRetryExpectingResult(
|
||||
[
|
||||
{
|
||||
statusCode: 400,
|
||||
result: null
|
||||
},
|
||||
{
|
||||
statusCode: 200,
|
||||
result: "Ok"
|
||||
}
|
||||
],
|
||||
null
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue