mirror of https://github.com/actions/cache.git
Compare commits
25 Commits
Author | SHA1 | Date |
---|---|---|
|
d9747005de | 5 years ago |
|
3f662ca624 | 5 years ago |
|
0232e3178d | 5 years ago |
|
ee7a57c615 | 5 years ago |
|
da9f90cb83 | 5 years ago |
|
ec7f7ebd08 | 5 years ago |
|
2a973a0f4e | 5 years ago |
|
cbbb8b4d4f | 5 years ago |
|
5a0add1806 | 5 years ago |
|
9fe7ad8b07 | 5 years ago |
|
7c7d003bbb | 5 years ago |
|
96e5a46c57 | 5 years ago |
|
84e606dfac | 5 years ago |
|
70655ec832 | 6 years ago |
|
fe1055e9d1 | 6 years ago |
|
a505c2e7a6 | 6 years ago |
|
10a14413e7 | 6 years ago |
|
cf4f44db70 | 6 years ago |
|
4c4974aff1 | 6 years ago |
|
cffae9552b | 6 years ago |
|
44543250bd | 6 years ago |
|
6491e51b66 | 6 years ago |
|
86dff562ab | 6 years ago |
|
0f810ad45a | 6 years ago |
|
9d8c7b4041 | 6 years ago |
@ -0,0 +1,144 @@
|
|||||||
|
import { retry } from "../src/cacheHttpClient";
|
||||||
|
import * as testUtils from "../src/utils/testUtils";
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
testUtils.clearInputs();
|
||||||
|
});
|
||||||
|
|
||||||
|
interface TestResponse {
|
||||||
|
statusCode: number;
|
||||||
|
result: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleResponse(
|
||||||
|
response: TestResponse | undefined
|
||||||
|
): Promise<TestResponse> {
|
||||||
|
if (!response) {
|
||||||
|
fail("Retry method called too many times");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode === 999) {
|
||||||
|
throw Error("Test Error");
|
||||||
|
} else {
|
||||||
|
return Promise.resolve(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testRetryExpectingResult(
|
||||||
|
responses: Array<TestResponse>,
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(actualResult.result).toEqual(expectedResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testRetryExpectingError(
|
||||||
|
responses: Array<TestResponse>
|
||||||
|
): Promise<void> {
|
||||||
|
responses = responses.reverse(); // Reverse responses since we pop from end
|
||||||
|
|
||||||
|
expect(
|
||||||
|
retry(
|
||||||
|
"test",
|
||||||
|
() => handleResponse(responses.pop()),
|
||||||
|
(response: TestResponse) => response.statusCode
|
||||||
|
)
|
||||||
|
).rejects.toBeInstanceOf(Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
test("retry works on successful response", async () => {
|
||||||
|
await testRetryExpectingResult(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
result: "Ok"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Ok"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("retry works after retryable status code", async () => {
|
||||||
|
await testRetryExpectingResult(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
statusCode: 503,
|
||||||
|
result: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
result: "Ok"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Ok"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("retry fails after exhausting retries", async () => {
|
||||||
|
await testRetryExpectingError([
|
||||||
|
{
|
||||||
|
statusCode: 503,
|
||||||
|
result: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 503,
|
||||||
|
result: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
result: "Ok"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("retry fails after non-retryable status code", async () => {
|
||||||
|
await testRetryExpectingError([
|
||||||
|
{
|
||||||
|
statusCode: 500,
|
||||||
|
result: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
result: "Ok"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("retry works after error", async () => {
|
||||||
|
await testRetryExpectingResult(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
statusCode: 999,
|
||||||
|
result: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
result: "Ok"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Ok"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("retry returns after client error", async () => {
|
||||||
|
await testRetryExpectingResult(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
statusCode: 400,
|
||||||
|
result: null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
result: "Ok"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
null
|
||||||
|
);
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Validate args
|
||||||
|
prefix="$1"
|
||||||
|
if [ -z "$prefix" ]; then
|
||||||
|
echo "Must supply prefix argument"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir test-cache
|
||||||
|
echo "$prefix $GITHUB_RUN_ID" > test-cache/test-file.txt
|
@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Validate args
|
||||||
|
prefix="$1"
|
||||||
|
if [ -z "$prefix" ]; then
|
||||||
|
echo "Must supply prefix argument"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Sanity check GITHUB_RUN_ID defined
|
||||||
|
if [ -z "$GITHUB_RUN_ID" ]; then
|
||||||
|
echo "GITHUB_RUN_ID not defined"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify file exists
|
||||||
|
file="test-cache/test-file.txt"
|
||||||
|
echo "Checking for $file"
|
||||||
|
if [ ! -e $file ]; then
|
||||||
|
echo "File does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify file content
|
||||||
|
content="$(cat $file)"
|
||||||
|
echo "File content:\n$content"
|
||||||
|
if [ -z "$(echo $content | grep --fixed-strings "$prefix $GITHUB_RUN_ID")" ]; then
|
||||||
|
echo "Unexpected file content"
|
||||||
|
exit 1
|
||||||
|
fi
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue