bito-code-review[bot] commented on PR #42012:
URL: https://github.com/apache/superset/pull/42012#issuecomment-4962914562

   <!-- Bito Reply -->
   The flagged issue is correct. Initializing `jest.useFakeTimers()` after 
`asyncEvent.init(config)` has already been called in the suite-level 
`beforeEach` can lead to a race condition where a real-timer polling loop 
continues to run, causing flaky test results. To resolve this, ensure 
`jest.useFakeTimers()` is called before any `init` call, or use a setup that 
avoids the real-timer initialization path.
   
   Here is the corrected implementation for the test case:
   
   ```typescript
       test('backs off exponentially when polling requests keep failing', async 
() => {
         jest.useFakeTimers();
         try {
           fetchMock.clearHistory().removeRoutes();
           fetchMock.get(EVENTS_ENDPOINT, { status: 403 });
           // Initialize after fake timers are active
           asyncEvent.init(config);
           asyncEvent.waitForAsyncData(asyncPendingEvent).catch(() => {});
   
           await jest.advanceTimersByTimeAsync(
             config.GLOBAL_ASYNC_QUERIES_POLLING_DELAY,
           );
           expect(fetchMock.callHistory.calls(EVENTS_ENDPOINT)).toHaveLength(1);
           // ... rest of the test
   ```
   
   There are no other comments on this PR to address.
   
   **superset-frontend/src/middleware/asyncEvent.test.ts**
   ```
   test('backs off exponentially when polling requests keep failing', async () 
=> {
         jest.useFakeTimers();
         try {
           fetchMock.clearHistory().removeRoutes();
           fetchMock.get(EVENTS_ENDPOINT, { status: 403 });
           // Initialize after fake timers are active
           asyncEvent.init(config);
           asyncEvent.waitForAsyncData(asyncPendingEvent).catch(() => {});
   
           await jest.advanceTimersByTimeAsync(
             config.GLOBAL_ASYNC_QUERIES_POLLING_DELAY,
           );
           expect(fetchMock.callHistory.calls(EVENTS_ENDPOINT)).toHaveLength(1);
   ```


-- 
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]

Reply via email to