Fix flaky integration test and clean up test patterns#1575
Open
Copilot wants to merge 8 commits into
Open
Conversation
The `setEnvironment persists selection` and `Project selection is independent of global` tests had a race condition where `getEnvironment` was called immediately after `setEnvironment` before the async config write had propagated. On slower CI runners, `getEnvironment` would fall back to auto-discovery and return `/usr/bin/python` instead of the newly-set environment. Fix: add `waitForCondition` (already imported) to poll until `getEnvironment` reflects the expected value before asserting, with a 15s timeout matching other tests in the file.
Copilot
AI
changed the title
[WIP] Fix flaky integration test due to race condition
Fix race condition in interpreter selection integration tests
Jun 10, 2026
The initial setEnvironment(undefined, oldEnv) fires an async event that could be captured by the TestEventHandler registered immediately after, causing the handler to see the wrong event. Add waitForCondition to ensure the initial environment is fully set before registering the handler.
Copilot
AI
changed the title
Fix race condition in interpreter selection integration tests
Fix race conditions in integration tests for interpreter selection
Jun 10, 2026
…uplicate getEnvironment calls
Copilot
AI
changed the title
Fix race conditions in integration tests for interpreter selection
Eliminate duplicate getEnvironment calls in integration tests
Jun 10, 2026
Copilot
AI
changed the title
Eliminate duplicate getEnvironment calls in integration tests
Fix flaky integration test and clean up test patterns
Jun 10, 2026
Fix two flaky tests in interpreterSelection.integration.test.ts that fail consistently on CI (all Python versions: 3.10, 3.12, 3.14): 1. 'Change event includes old and new values': setEnvironment fires events via setImmediate(), so the handler created immediately after the first setEnvironment call caught the stale event instead of the intended one. Added settle time and now searches for the specific matching event instead of using handler.last. 2. 'Setting same environment is idempotent': The underlying manager's onDidChangeEnvironment can trigger refreshEnvironment(), firing events even on same-value sets. Changed assertion to verify that if events fire, they don't indicate an actual change (old === new), rather than asserting no events fire at all. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The "Change event includes old and new values" test had a race condition:
setEnvironment(undefined, oldEnv)fires an async event that could be captured by theTestEventHandlerregistered immediately after, causing the handler to see the wrong event.Changes
waitForConditionbetween the initialsetEnvironmentand handler registration to ensure the first event has fully propagatedgetEnvironmentcalls: The original pattern calledwaitForCondition(pollinggetEnvironmentuntil ready) then immediately re-fetched and asserted on a secondgetEnvironmentcall. Combined these by capturing the result inside thewaitForConditioncallback:setTimeoutwithwaitForConditionin the idempotency test — a fixed 500ms sleep is fragile on slow CI runnersPythonEnvironmentinstead of repeated inlineimport('../../api').PythonEnvironmenttype expressions