mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-08-15 10:23:43 +00:00
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:
+7
-2
@@ -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}`,
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user