feat: rate limit error chaching (#2448)

* feat: rate limit error chaching

Rate limit error caching to alleviate PATs.

* refactor: improve code comments
This commit is contained in:
Rick Staa
2023-09-17 15:45:17 +02:00
committed by GitHub
parent 64f56e88b4
commit bc8eaecaf4
9 changed files with 54 additions and 18 deletions
+7 -2
View File
@@ -184,13 +184,18 @@ describe("Test /api/", () => {
]);
});
it("should not store cache when error", async () => {
it("should set shorter cache when error", async () => {
const { req, res } = faker({}, error);
await api(req, res);
expect(res.setHeader.mock.calls).toEqual([
["Content-Type", "image/svg+xml"],
["Cache-Control", `no-cache, no-store, must-revalidate`],
[
"Cache-Control",
`max-age=${CONSTANTS.ERROR_CACHE_SECONDS / 2}, s-maxage=${
CONSTANTS.ERROR_CACHE_SECONDS
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
],
]);
});
+2 -2
View File
@@ -1,6 +1,6 @@
import { jest } from "@jest/globals";
import "@testing-library/jest-dom";
import { retryer } from "../src/common/retryer.js";
import { retryer, RETRIES } from "../src/common/retryer.js";
import { logger } from "../src/common/utils.js";
import { expect, it, describe } from "@jest/globals";
@@ -44,7 +44,7 @@ describe("Test Retryer", () => {
try {
await retryer(fetcherFail, {});
} catch (err) {
expect(fetcherFail).toBeCalledTimes(8);
expect(fetcherFail).toBeCalledTimes(RETRIES + 1);
expect(err.message).toBe("Downtime due to GitHub API rate limiting");
}
});