← All Scenarios
· Scenario 07
RunspacePool Exhaustion With Bounded Wait
Goal
Verify that PSInvocationSettings.Timeout bounds the wait when asking a RunspacePool for a runspace and all slots are busy.
Trying to break
Before the fix: CoreInvokeHelper calls WaitOne() forever if pool is full. After the fix: WaitOne(settings.Timeout) throws TimeoutException when the pool is exhausted. Pool min=1 max=1, occupy it, then try a second invocation with a 2s timeout.
2 test stepsPress Start to walk through the scenario step by step.
View full script source (pool-exhaustion.ps1)
$pool = [RunspaceFactory]::CreateRunspacePool(1, 1)
$pool.Open()
$ps1 = [PowerShell]::Create()
$ps1.RunspacePool = $pool
$ps1.AddScript('Start-Sleep -Seconds 30') > $null
$null = $ps1.BeginInvoke()
Start-Sleep -Milliseconds 300 # let ps1 acquire the runspace
$ps2 = [PowerShell]::Create()
$ps2.RunspacePool = $pool
$ps2.AddScript('1') > $null
$settings = [PSInvocationSettings]::new()
$settings.Timeout = [TimeSpan]::FromSeconds(2)
try {
$ps2.Invoke($null, $settings)
} catch [TimeoutException] {
Write-Host 'PASS: TimeoutException from pool exhaustion'
}