test: fix CI OOM crashes in DatasourceControl test and flaky FileHandleer test#38430
test: fix CI OOM crashes in DatasourceControl test and flaky FileHandleer test#38430
Conversation
DatasourceControl.test.tsx consistently OOM-crashes Jest workers in CI because the last 4 tests render the full DatasourceEditor (2,500+ lines, 150+ imports) without mocking. Each test mounts this massive tree, compounding memory until crash. Mock DatasourceEditor with a lightweight stub since these tests only verify DatasourceControl's callback wiring through the modal save flow, not editor internals (covered by DatasourceEditor.test.tsx). Also scope the SupersetClient.get spy into its single consuming test with explicit restore to eliminate cross-test mock leaks, fix missing await on userEvent calls, and rename tests to reflect their actual scope. Results: heap 615MB→287MB, heavy tests 5500ms→350ms each. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Prevent re-introducing the OOM crash fixed in fe5f0b0 by adding: - fetchMock unmatched call assertion in afterEach (catches leaked routes) - pre-commit hook banning mockImplementationOnce in DatasourceControl tests - scoped ESLint await-async-events rule for this test file - CI heap-check job with 520MB threshold, mockImpl guard, and await guard Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR reduces Superset frontend CI flakiness by lowering Jest memory pressure in DatasourceControl unit tests and cleaning up a timer leak in FileHandler tests, while adding CI guards to prevent regressions.
Changes:
- Mock
DatasourceEditorinDatasourceControl.test.tsx, simplify save-flow tests, and add stricter fetch-mock cleanup checks to prevent Jest worker OOMs. - Fix
FileHandlertest flakiness by tracking and clearing pendingsetTimeoutwork between tests. - Add targeted lint/pre-commit/CI guards (heap threshold, banned
mockImplementationOnce, and un-awaiteduserEventchecks).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
superset-frontend/src/pages/FileHandler/index.test.tsx |
Clears leaked timers and resets window.launchQueue to prevent cross-test interference. |
superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx |
Mocks heavy editor component, improves async event handling, and adds fetch-mock leak detection to stabilize CI memory usage. |
superset-frontend/.eslintrc.js |
Adds a file-scoped rule requiring awaited userEvent calls for the targeted test file. |
.pre-commit-config.yaml |
Adds a pre-commit guard intended to ban mockImplementationOnce in the targeted test file. |
.github/workflows/superset-frontend.yml |
Adds a dedicated CI job to enforce heap usage and regression guards for the DatasourceControl test. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
133127c to
b951139
Compare
superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
Show resolved
Hide resolved
superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
Show resolved
Hide resolved
superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
Outdated
Show resolved
Hide resolved
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Track pending setTimeout IDs in a Set instead of a single variable to avoid orphaning timers if setConsumer is called multiple times. Replace raw DOM .click() with await userEvent.click() to respect React async/act boundaries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Revert the pre-commit hook, scoped ESLint rule, and CI heap check job added in 289aa1e. These single-test guards don't scale; the DatasourceEditor mock is the actual OOM fix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b951139 to
18de6a4
Compare
Ensure cleanup (clearHistory, removeRoutes, restoreAllMocks) runs even when the unmatched-call guard throws, preventing cascading failures in subsequent tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
61d8314 to
0e7b9dd
Compare
Code Review Agent Run #7629e9Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
SUMMARY
Fixes consistent Jest worker OOM crashes in master CI (
sharded-jest-testsshard 7, sometimes 5/6) and a flaky FileHandler test.DatasourceControl OOM fix (
fe5f0b0):DatasourceEditor(2,620 lines, 150+ imports) inDatasourceControl.test.tsx— the heavy editor was rendered 4+ times per shard without mocking, compounding memory until the Jest worker crashedmockImplementationOnce), await alluserEventcalls, use named fetchMock routes with proper cleanupRegression guards (
289aa1e):afterEachassertion for unmatched fetchMock calls (catches leaked routes)mockImplementationOncein DatasourceControl teststesting-library/await-async-eventsrule for this test fileFileHandler flaky test fix (
471205c):setupLaunchQueueusedsetTimeout(fn, 0)without cleanup — pending timers leaked between testsafterEachBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — test-only changes
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION
🤖 Generated with Claude Code