Skip to content

Commit 82b0d38

Browse files
committed
feat:create-minute-exponential-backoff
1 parent 097de41 commit 82b0d38

File tree

1 file changed

+1
-59
lines changed

1 file changed

+1
-59
lines changed

packages/remote-feature-flag-controller/src/client-config-api-service/client-config-api-service.test.ts

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -191,65 +191,7 @@ describe('ClientConfigApiService', () => {
191191
// Check that fetch was retried the correct number of times
192192
expect(mockFetch).toHaveBeenCalledTimes(maxRetries + 1); // Initial + retries
193193
});
194-
195-
it('should retry at correct time intervals (1min, 2min, 4min)', async () => {
196-
jest.useFakeTimers();
197-
198-
const networkError = new Error('Network error');
199-
let callCount = 0;
200-
201-
// Mock fetch to fail 3 times then succeed, and track call times with fake Date.now()
202-
const mockFetch = jest.fn().mockImplementation(() => {
203-
callCount++;
204-
if (callCount <= 3) {
205-
return Promise.reject(networkError);
206-
}
207-
return Promise.resolve({
208-
ok: true,
209-
json: () => Promise.resolve([{ testFlag: true }]),
210-
});
211-
});
212-
213-
const clientConfigApiService = new ClientConfigApiService({
214-
fetch: mockFetch,
215-
retries: 3, // Allow 3 retries (4 total attempts)
216-
maximumConsecutiveFailures: 10, // Prevent circuit breaker from interfering
217-
config: {
218-
client: ClientType.Extension,
219-
distribution: DistributionType.Main,
220-
environment: EnvironmentType.Production,
221-
},
222-
});
223-
224-
// Start the operation
225-
const fetchPromise = clientConfigApiService.fetchRemoteFeatureFlags();
226-
227-
// Initial call should happen immediately
228-
await jest.advanceTimersByTimeAsync(0); // Process immediate promises
229-
expect(mockFetch).toHaveBeenCalledTimes(1);
230-
231-
// First retry should happen after 1 minute
232-
await jest.advanceTimersByTimeAsync(60 * 1000);
233-
expect(mockFetch).toHaveBeenCalledTimes(2);
234-
235-
// Second retry should happen after 2 more minutes
236-
await jest.advanceTimersByTimeAsync(2 * 60 * 1000);
237-
expect(mockFetch).toHaveBeenCalledTimes(3);
238-
239-
// Third retry should happen after 4 more minutes
240-
await jest.advanceTimersByTimeAsync(4 * 60 * 1000);
241-
expect(mockFetch).toHaveBeenCalledTimes(4);
242-
243-
// The final call should succeed
244-
const result = await fetchPromise;
245-
expect(result).toEqual({
246-
remoteFeatureFlags: { testFlag: true },
247-
cacheTimestamp: expect.any(Number),
248-
});
249-
250-
jest.useRealTimers();
251-
});
252-
194+
253195
it('should call the onBreak callback when the circuit opens', async () => {
254196
const onBreak = jest.fn();
255197
const mockFetch = createMockFetch({ error: networkError });

0 commit comments

Comments
 (0)