← All Scenarios
· Scenario 05
Runspace Close With Active Pipeline
Goal
Verify Runspace.Close() triggers the new parallel StopPipelines() and completes within the 30s + overhead deadline instead of hanging forever.
Trying to break
Before the fix: Close → sequential Stop → pipeline WaitOne(∞) = potential hang. Tests single pipeline and 3 simultaneous pipelines to stress the parallel stop path.
2 test stepsPress Start to walk through the scenario step by step.
View full script source (runspace-close-with-pipeline.ps1)
$rs = [RunspaceFactory]::CreateRunspace()
$rs.Open()
$ps = [PowerShell]::Create()
$ps.Runspace = $rs
$ps.AddScript('Start-Sleep -Seconds 300') > $null
$null = $ps.BeginInvoke()
Start-Sleep -Milliseconds 300
$sw = [Diagnostics.Stopwatch]::StartNew()
$rs.Close() # must not hang
$sw.Stop()
Write-Host "Close completed in $($sw.ElapsedMilliseconds)ms"