Skip to content

fix(tests): fix flaky FileHandler test by removing setTimeout-based LaunchQueue mock#39508

Draft
mistercrunch wants to merge 1 commit intoapache:masterfrom
mistercrunch:fix-filehandler-flaky-tests
Draft

fix(tests): fix flaky FileHandler test by removing setTimeout-based LaunchQueue mock#39508
mistercrunch wants to merge 1 commit intoapache:masterfrom
mistercrunch:fix-filehandler-flaky-tests

Conversation

@mistercrunch
Copy link
Copy Markdown
Member

SUMMARY

Fixes flaky FileHandler/index.test.tsx tests that intermittently timeout at 20s. The flakiness was observed on multiple tests including 'handles Parquet file correctly' and 'handles Excel (.xls) file correctly' (e.g. GHA job 71282515731 on PR #39345).

Root cause: setupLaunchQueue used setTimeout(fn, 0) to auto-fire the LaunchQueue consumer callback. This caused:

  1. The consumer executed outside React's act() boundary (in a macrotask), so state updates weren't flushed reliably
  2. The async consumer promise wasn't tracked, so in-flight work from one test could bleed into the next test
  3. Any test using setupLaunchQueue(fileHandle) could fail non-deterministically

Fix:

  • Call the consumer synchronously from setConsumer instead of via setTimeout — this runs within React's act() boundary since setConsumer is called from useEffect
  • Track the async consumer promise and await it in afterEach to ensure all async work completes before the next test starts
  • Remove the now-unnecessary pendingTimerIds timer tracking

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A - test-only change

TESTING INSTRUCTIONS

  • Run cd superset-frontend && npm run test -- src/pages/FileHandler/index.test.tsx and verify all 10 tests pass (1 skipped)
  • Run the test file multiple times to confirm no flakiness

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

…aunchQueue mock

Replace setTimeout-based consumer auto-firing in setupLaunchQueue with
synchronous invocation. The setTimeout caused the consumer callback to
execute outside React's act() boundary, leading to unflushed state
updates and test timeouts. Track the async consumer promise in afterEach
to ensure in-flight work completes before the next test starts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 21, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 4961039
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69e71cd29cd2350008c4800a
😎 Deploy Preview https://deploy-preview-39508--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant