aminghadersohi commented on code in PR #42012:
URL: https://github.com/apache/superset/pull/42012#discussion_r3574648568
##########
superset-frontend/src/middleware/asyncEvent.test.ts:
##########
@@ -173,6 +173,91 @@ describe('asyncEvent middleware', () => {
expect(fetchMock.callHistory.calls(CACHED_DATA_ENDPOINT)).toHaveLength(1);
});
+ test('backs off exponentially when polling requests keep failing', async
() => {
+ // stop the real-timer polling loop started by beforeEach before
+ // switching to fake timers, so all polls run on the fake clock
+ mockedIsFeatureEnabled.mockReturnValueOnce(false);
+ asyncEvent.init(config);
+ jest.useFakeTimers();
+ try {
+ fetchMock.clearHistory().removeRoutes();
+ fetchMock.get(EVENTS_ENDPOINT, { status: 403 });
+ asyncEvent.init(config);
+ asyncEvent.waitForAsyncData(asyncPendingEvent).catch(() => {});
+
+ // first poll fires after the configured delay and fails
+ await jest.advanceTimersByTimeAsync(
+ config.GLOBAL_ASYNC_QUERIES_POLLING_DELAY,
+ );
+ expect(fetchMock.callHistory.calls(EVENTS_ENDPOINT)).toHaveLength(1);
+
+ // next poll is delayed by 2x the configured delay, so nothing yet
+ await jest.advanceTimersByTimeAsync(
+ config.GLOBAL_ASYNC_QUERIES_POLLING_DELAY,
+ );
+ expect(fetchMock.callHistory.calls(EVENTS_ENDPOINT)).toHaveLength(1);
+
+ await jest.advanceTimersByTimeAsync(
+ config.GLOBAL_ASYNC_QUERIES_POLLING_DELAY,
+ );
+ expect(fetchMock.callHistory.calls(EVENTS_ENDPOINT)).toHaveLength(2);
+
+ // after the second failure the delay grows to 4x
+ await jest.advanceTimersByTimeAsync(
+ 3 * config.GLOBAL_ASYNC_QUERIES_POLLING_DELAY,
+ );
+ expect(fetchMock.callHistory.calls(EVENTS_ENDPOINT)).toHaveLength(2);
+
+ await jest.advanceTimersByTimeAsync(
+ config.GLOBAL_ASYNC_QUERIES_POLLING_DELAY,
+ );
+ expect(fetchMock.callHistory.calls(EVENTS_ENDPOINT)).toHaveLength(3);
Review Comment:
MEDIUM: Could we add coverage for the advertised 60-second cap? This test
stops after three failures, and the reset test reaches only two, so neither
exercises the `Math.min(..., MAX_ERROR_POLLING_DELAY_MS)` branch. With the 50
ms test delay, the cap is first selected at failure 11; please assert no
request at 59,999 ms, one at 60,000 ms, and that additional failures remain
capped.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]