This is an automated email from the ASF dual-hosted git repository.

jli pushed a commit to branch fix-master-ci
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/fix-master-ci by this push:
     new 471205c5fd test(FileHandler): fix flaky test by cleaning up leaked 
setTimeout
471205c5fd is described below

commit 471205c5fd4bb895e616c6482614637dbbfdd7a7
Author: Joe Li <[email protected]>
AuthorDate: Wed Mar 4 22:51:14 2026 -0800

    test(FileHandler): fix flaky test by cleaning up leaked setTimeout
    
    The setupLaunchQueue helper used setTimeout(fn, 0) to defer the
    consumer callback but never cleaned up the timer. Under CI load,
    pending timers from one test could fire during the next test's
    execution, causing non-deterministic behavior.
    
    Store the timer ID and clear it in afterEach to prevent leaks.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 superset-frontend/src/pages/FileHandler/index.test.tsx | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/superset-frontend/src/pages/FileHandler/index.test.tsx 
b/superset-frontend/src/pages/FileHandler/index.test.tsx
index aa0c9d9bab..543f797950 100644
--- a/superset-frontend/src/pages/FileHandler/index.test.tsx
+++ b/superset-frontend/src/pages/FileHandler/index.test.tsx
@@ -108,6 +108,8 @@ type LaunchQueue = {
   ) => void;
 };
 
+let pendingTimerId: ReturnType<typeof setTimeout> | null = null;
+
 const setupLaunchQueue = (fileHandle: MockFileHandle | null = null) => {
   let savedConsumer:
     | ((params: { files?: MockFileHandle[] }) => void | Promise<void>)
@@ -116,7 +118,8 @@ const setupLaunchQueue = (fileHandle: MockFileHandle | null 
= null) => {
     setConsumer: (consumer: (params: { files?: MockFileHandle[] }) => void) => 
{
       savedConsumer = consumer;
       if (fileHandle) {
-        setTimeout(() => {
+        pendingTimerId = setTimeout(() => {
+          pendingTimerId = null;
           consumer({
             files: [fileHandle],
           });
@@ -136,6 +139,14 @@ beforeEach(() => {
   delete (window as any).launchQueue;
 });
 
+afterEach(() => {
+  if (pendingTimerId !== null) {
+    clearTimeout(pendingTimerId);
+    pendingTimerId = null;
+  }
+  delete (window as any).launchQueue;
+});
+
 test('shows error when launchQueue is not supported', async () => {
   render(
     <MemoryRouter initialEntries={['/superset/file-handler']}>

Reply via email to