Fix flakey ModelPicker test #4972
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From Roo Code:
I successfully fixed the flaky
ModelPicker.spec.tsxtest by addressing timeout management issues that were causing "timeout after test environment was torn down" errors.Changes Made:
1. Component Changes (
ModelPicker.tsx):selectTimeoutRefandcloseTimeoutRefto tracksetTimeoutcallsonSelect: Now clears existing timeouts before setting new onesonOpenChange: Now clears existing timeouts before setting new ones2. Test Changes (
ModelPicker.spec.tsx):vi.useFakeTimers()inbeforeEachvi.clearAllTimers()andvi.useRealTimers()inafterEachsetTimeoutpromises tovi.advanceTimersByTime(100)for deterministic timingRoot Cause:
The original issue was that
setTimeoutcalls in theModelPickercomponent were creating timers that outlived the test environment, causing them to fire after test cleanup and resulting in the "timeout after test environment was torn down" error.Result:
The tests now run consistently and are no longer flaky. The timeout management ensures proper cleanup both at the component level and test level, preventing resource leaks and timing-related test failures.
Important
Fixes flaky
ModelPickertest by improving timeout management in component and tests.ModelPicker.tsx:selectTimeoutRefandcloseTimeoutRefto tracksetTimeoutcalls.onSelectandonOpenChangeto clear existing timeouts before setting new ones.useEffectfor cleanup of timeouts on component unmount.ModelPicker.spec.tsx:vi.useFakeTimers()inbeforeEachandvi.clearAllTimers()inafterEach.setTimeoutpromises withvi.advanceTimersByTime(100)for deterministic timing.This description was created by
for 753c959. You can customize this summary. It will automatically update as commits are pushed.