Skip to content

Commit

Permalink
giving a bit of wait time to Assert-RunspaceCount
Browse files Browse the repository at this point in the history
  • Loading branch information
santisq committed Jun 26, 2024
1 parent 4d08cad commit 7e58b70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tests/PSParallelPipeline.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ Describe PSParallelPipeline {

Context 'TimeoutSeconds Parameter' {
It 'Stops processing after the specified seconds' {
$wait = 5
if (-not $IsCoreCLR) {
# because pwsh 5.1 fucking sucks!
$wait = 10
}

Assert-RunspaceCount {
$timer = [Stopwatch]::StartNew()
{
Expand All @@ -150,7 +156,7 @@ Describe PSParallelPipeline {
} | Should -Throw -ExceptionType ([TimeoutException])
$timer.Stop()
$timer.Elapsed | Should -BeLessOrEqual ([timespan]::FromSeconds(2.2))
}
} -WaitSeconds $wait
}
}

Expand Down
7 changes: 5 additions & 2 deletions tests/common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ function Assert-RunspaceCount {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[scriptblock] $ScriptBlock
[scriptblock] $ScriptBlock,

[Parameter()]
[int] $WaitSeconds = 5
)

try {
$count = @(Get-Runspace).Count
& $ScriptBlock
}
finally {
Start-Sleep 5
Start-Sleep $WaitSeconds
Get-Runspace |
Should -HaveCount $count -Because 'Runspaces should be correctly disposed'
}
Expand Down

0 comments on commit 7e58b70

Please sign in to comment.