Skip to content

Commit cda7458

Browse files
sadpandajoeclaude
andcommitted
fix(dashboard): eliminate race condition in FiltersConfigModal test
The "validates the pre-filter value" test had a race condition that caused intermittent failures and required a 50-second timeout. **Root Cause:** - Test used synchronous `userEvent.click()` calls - Immediately called `jest.runOnlyPendingTimers()` (wrong method) - User interactions didn't complete before timer flush - Created race where validation timers might not execute **Fix:** - Await `userEvent.click()` calls (v12-compatible async approach) - Use `jest.runAllTimers()` instead of `runOnlyPendingTimers()` - Wrap timer manipulation in try/finally for cleanup - Add explicit `waitFor()` after restoring timers **Results:** - Test now passes consistently (3/3 runs) - Runs in ~25-29s vs 50s timeout - No regressions (16 passed, 2 skipped) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent de5ca79 commit cda7458

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.test.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,21 @@ test.skip('validates the default value', async () => {
337337

338338
test('validates the pre-filter value', async () => {
339339
jest.useFakeTimers();
340+
try {
341+
defaultRender();
340342

341-
defaultRender();
343+
await userEvent.click(screen.getByText(FILTER_SETTINGS_REGEX));
344+
await userEvent.click(getCheckbox(PRE_FILTER_REGEX));
342345

343-
userEvent.click(screen.getByText(FILTER_SETTINGS_REGEX));
344-
userEvent.click(getCheckbox(PRE_FILTER_REGEX));
345-
346-
jest.runOnlyPendingTimers();
347-
jest.useRealTimers();
346+
jest.runAllTimers();
347+
} finally {
348+
jest.useRealTimers();
349+
}
348350

349-
expect(
350-
await screen.findByText(PRE_FILTER_REQUIRED_REGEX),
351-
).toBeInTheDocument();
352-
}, 50000); // Slow-running test, increase timeout to 50 seconds.
351+
await waitFor(() => {
352+
expect(screen.getByText(PRE_FILTER_REQUIRED_REGEX)).toBeInTheDocument();
353+
});
354+
});
353355

354356
// eslint-disable-next-line jest/no-disabled-tests
355357
test.skip("doesn't render time range pre-filter if there are no temporal columns in datasource", async () => {

0 commit comments

Comments
 (0)