Skip to content

Conversation

@cte
Copy link
Collaborator

@cte cte commented Jun 21, 2025

From Roo Code:

I successfully fixed the flaky ModelPicker.spec.tsx test by addressing timeout management issues that were causing "timeout after test environment was torn down" errors.

Changes Made:

1. Component Changes (ModelPicker.tsx):

  • Added timeout refs: selectTimeoutRef and closeTimeoutRef to track setTimeout calls
  • Enhanced onSelect: Now clears existing timeouts before setting new ones
  • Enhanced onOpenChange: Now clears existing timeouts before setting new ones
  • Added cleanup useEffect: Ensures all timeouts are cleared when component unmounts

2. Test Changes (ModelPicker.spec.tsx):

Root Cause:

The original issue was that setTimeout calls in the ModelPicker component 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 ModelPicker test by improving timeout management in component and tests.

  • Component Changes in ModelPicker.tsx:
    • Added selectTimeoutRef and closeTimeoutRef to track setTimeout calls.
    • Enhanced onSelect and onOpenChange to clear existing timeouts before setting new ones.
    • Added useEffect for cleanup of timeouts on component unmount.
  • Test Changes in ModelPicker.spec.tsx:
    • Added vi.useFakeTimers() in beforeEach and vi.clearAllTimers() in afterEach.
    • Replaced setTimeout promises with vi.advanceTimersByTime(100) for deterministic timing.
    • Added timer advancement after model selections to ensure timeouts are processed.

This description was created by Ellipsis for 753c959. You can customize this summary. It will automatically update as commits are pushed.

@cte cte requested review from jr and mrubens as code owners June 21, 2025 07:19
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 21, 2025
@cte cte merged commit 00ad425 into main Jun 21, 2025
19 checks passed
@cte cte deleted the cte/fix-flakey-tests branch June 21, 2025 07:34
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 21, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jun 21, 2025
cte added a commit that referenced this pull request Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants