Fix flaky Debug-Runspace attach event test - #27885
Open
Travis Plunk (TravisEz13) wants to merge 3 commits into
Open
Fix flaky Debug-Runspace attach event test#27885Travis Plunk (TravisEz13) wants to merge 3 commits into
Travis Plunk (TravisEz13) wants to merge 3 commits into
Conversation
The test started a 'Wait-Event' pipeline with BeginInvoke on a PowerShell instance whose runspace was not yet opened, then immediately started Debug-Runspace against that runspace id. Nothing synchronized the two, so Debug-Runspace could run before the target runspace was open/executing, in which case the cmdlet errored out or skipped the null-conditional Events.GenerateEvent call and OnDebugAttach never fired. Open the target runspace explicitly, gate on the Wait-Event pipeline actually running before attaching, wait deterministically for detach, and dispose all instances in a finally block. Assertions are unchanged and no production code was modified. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2a30274b-8dba-4f6b-92b3-e715b633f8b3
Keep the original five-second assertion timeout and avoid broad silent catches in cleanup while preserving deterministic readiness and teardown.
Preserve best-effort cleanup while surfacing stop failures instead of suppressing them silently.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Debug-Runspace Pester test to eliminate a race condition by explicitly opening the target runspace and synchronizing on the Wait-Event pipeline reaching a running/busy state before invoking Debug-Runspace. The change is test-only and aims to prevent intermittent CI failures where the OnDebugAttach event was not observed.
Changes:
- Create and open a dedicated target runspace up front, and run
Wait-Eventinside it to ensure the event manager is initialized before attach. - Add deterministic synchronization via
Wait-UntilTrueto confirm theWait-Eventpipeline is actually running (and the runspace is busy) before attaching the debugger. - Add robust cleanup via
try/finallyto stop and dispose the debugger, target pipeline, and runspace (with warnings only on best-effort cleanup failures).
π‘ Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Aditya Patwardhan (adityapatwardhan)
approved these changes
Aug 27, 2026
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.
PR Summary
Make the
Debug-Runspaceattach-event test deterministic by opening the target runspace explicitly and waiting for the asynchronousWait-Eventpipeline to reach a running, busy state before invoking the debugger. Ensure the debugger, target pipeline, and runspace are cleaned up in all outcomes, while warning if best-effort stop cleanup fails.PR Context
The test could start
Debug-Runspacebefore the target runspace had opened and registered its event waiter, causing intermittent Windows CI failures whenOnDebugAttachwas not observed. This is a test-only synchronization fix; production code is unchanged. The original attach, attached-state, stop, and detach-state assertions remain intact.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerTest Results
Debug-Runspace.Tests.ps1: 5 passed, 0 failedStart-PSPester: 25 passed, 0 failed