Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/functions/TestRegistry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ function Invoke-TestRegistryWithRetry {
catch [System.IO.IOException] {
# when running in parallel this occasionally triggers
# IOException: No more data is available
# let's just retry the operation
& $SafeCommands['Write-Warning'] "IO exception during a TestRegistry operation, retrying."
# let's just retry the operation. The operations we wrap are idempotent, so a retry that
# succeeds leaves no trace for the user to act on, and a retry that fails rethrows and the
# exception is the signal. Either way a warning is just noise, so this is a debug message.
if ($PesterPreference.Debug.WriteDebugMessages.Value) {
Write-PesterDebugMessage -Scope Runtime "IO exception during a TestRegistry operation, retrying."
}
& $ScriptBlock
}
}
Expand Down
17 changes: 17 additions & 0 deletions tst/functions/TestRegistry.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ Describe 'Invoke-TestRegistryWithRetry' {
}
}

It 'Does not warn when the retry recovers' {
InModuleScope -ModuleName Pester {
$calls = @{ Count = 0 }
$streams = Invoke-TestRegistryWithRetry {
$calls.Count++
if ($calls.Count -eq 1) {
throw [System.IO.IOException] 'No more data is available'
}
'recovered'
} 3>&1

$calls.Count | Should -Be 2
@($streams | Where-Object { $_ -is [System.Management.Automation.WarningRecord] }) |
Should -BeNullOrEmpty -Because 'a recovered retry is idempotent, so there is nothing for the user to act on'
}
}

It 'Rethrows when the transient IOException persists on retry' {
InModuleScope -ModuleName Pester {
{ Invoke-TestRegistryWithRetry { throw [System.IO.IOException] 'No more data is available' } } |
Expand Down
Loading