Skip to content

Commit daed6d4

Browse files
authored
Test/quota monitor massive scaling (JhaSourav07#3302)
## Description Fixes JhaSourav07#2924 Added comprehensive massive scaling and high-bound stability tests for the quota monitor service. ### Changes Made * Created `services/github/quota-monitor.massive-scaling.test.ts` * Added coverage for extremely large GitHub quota values * Verified handling of thousands of refresh events without state corruption * Tested quota calculations with `Number.MAX_SAFE_INTEGER` * Simulated massive contributor activity datasets to validate stability under high load * Verified singleton behavior remains consistent under high-volume access patterns * Included basic performance validation for large iteration scenarios ### Test Coverage 1. Massive quota header values handling 2. High-volume refresh count tracking 3. Extreme upper-bound quota calculations 4. Large contributor activity dataset simulation 5. Singleton stability under repeated access All tests pass successfully with Vitest. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Tests) ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally. * [x] I have run formatting checks and resolved issues. * [x] My commits follow the Conventional Commits format. * [ ] I have updated `README.md` if required. * [x] I have starred the repo. * [x] I have made sure that I have only one commit to merge in this PR. * [x] The SVG output is unaffected by these changes. * [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 388ec3a + e6e9404 commit daed6d4

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { beforeEach, describe, expect, it } from 'vitest';
2+
import quotaMonitor, { QuotaMonitor } from './quota-monitor';
3+
4+
describe('QuotaMonitor massive scaling stability', () => {
5+
beforeEach(() => {
6+
quotaMonitor.reset();
7+
});
8+
9+
it('handles massive quota header values without breaking state', () => {
10+
const headers = {
11+
'x-ratelimit-limit': '1000000000',
12+
'x-ratelimit-remaining': '999999999',
13+
'x-ratelimit-reset': '9999999999',
14+
};
15+
16+
quotaMonitor.updateQuotaFromHeaders(headers);
17+
18+
expect(quotaMonitor.getQuota()).toEqual({
19+
limit: 1000000000,
20+
remaining: 999999999,
21+
resetTime: 9999999999 * 1000,
22+
totalRefreshes: 0,
23+
});
24+
});
25+
26+
it('handles thousands of refresh count increments efficiently', () => {
27+
const start = performance.now();
28+
29+
for (let i = 0; i < 10_000; i++) {
30+
quotaMonitor.incrementRefreshCount();
31+
}
32+
33+
const duration = performance.now() - start;
34+
const quota = quotaMonitor.getQuota();
35+
36+
expect(quota.totalRefreshes).toBe(10_000);
37+
expect(duration).toBeLessThan(100);
38+
});
39+
40+
it('keeps quota low calculation stable with extreme high bounds', () => {
41+
quotaMonitor.setQuota(Number.MAX_SAFE_INTEGER, 1, Date.now());
42+
43+
const quota = quotaMonitor.getQuota();
44+
45+
expect(Number.isFinite(quota.limit)).toBe(true);
46+
expect(Number.isFinite(quota.remaining)).toBe(true);
47+
expect(Number.isFinite(quota.resetTime)).toBe(true);
48+
expect(quotaMonitor.isQuotaLow()).toBe(true);
49+
});
50+
51+
it('does not overflow or corrupt state with massive mocked contributor actions', () => {
52+
const contributorActions = Array.from({ length: 25_000 }, (_, index) => ({
53+
username: `contributor-${index}`,
54+
commits: index + 1,
55+
pullRequests: index % 50,
56+
reviews: index % 20,
57+
}));
58+
59+
const totalActivity = contributorActions.reduce(
60+
(total, action) => total + action.commits + action.pullRequests + action.reviews,
61+
0
62+
);
63+
64+
quotaMonitor.setQuota(totalActivity, Math.floor(totalActivity * 0.75), Date.now() + 60_000);
65+
66+
const quota = quotaMonitor.getQuota();
67+
68+
expect(contributorActions).toHaveLength(25_000);
69+
expect(Number.isFinite(totalActivity)).toBe(true);
70+
expect(quota.limit).toBe(totalActivity);
71+
expect(quota.remaining).toBe(Math.floor(totalActivity * 0.75));
72+
expect(quotaMonitor.isQuotaLow()).toBe(false);
73+
});
74+
75+
it('returns the same singleton instance for high-volume access patterns', () => {
76+
const instances = Array.from({ length: 5_000 }, () => QuotaMonitor.getInstance());
77+
78+
expect(instances.every((instance) => instance === quotaMonitor)).toBe(true);
79+
});
80+
});

0 commit comments

Comments
 (0)