pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.11k stars 473 forks source link

New-RandomTempRegistry: Test-Path : No more data is available #2418

Open chrisdent-de opened 10 months ago

chrisdent-de commented 10 months ago

Checklist

What is the issue?

When Pester 5 is running in parallel the Test-Path invocation in New-RandomTempRegistry will occasionally throw No more data is available.

This error is already handled with a retry for New-Item, but not the Test-Path command.

Expected Behavior

The TestRegistry drive should successfully create.

Steps To Reproduce

Cannot trivially reproduce this transient error.

Stack trace is shown below:

Running tests from 'SomeTests.Tests.ps1'
PS>TerminatingError(Test-Path): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No more data is available.
"
>> TerminatingError(Test-Path): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No more data is available.
"
>> TerminatingError(Test-Path): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No more data is available.
"
>> TerminatingError(Test-Path): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No more data is available.
"
Framework failed:
Result :Error :Test-Path : No more data is available.

...\pester\Pester.psm1:15947 char:20
+ ... ntil (-not (& $SafeCommands['Test-Path'] -Path $Path -PathType Contai ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (HKEY_CURRENT_US...8d-5e6a300e12fc:String) [Test-Path], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.TestPathCommand

New-RandomTempRegistry, ...\pester\Pester.psm1: line 15946
New-TestRegistry, ...\pester\Pester.psm1: line 15868
<ScriptBlock>, ...\pester\Pester.psm1: line 16009
<ScriptBlock>, ...\pester\Pester.psm1: line 1985
<ScriptBlock>, ...\pester\Pester.psm1: line 1959
Invoke-ScriptBlock, ...\pester\Pester.psm1: line 2123
Invoke-Block, ...\pester\Pester.psm1: line 856
<ScriptBlock>, ...\pester\Pester.psm1: line 1672
<ScriptBlock>, ...\pester\Pester.ps1: line 3
<ScriptBlock>, ...\pester\Pester.psm1: line 3164
Invoke-InNewScriptScope, ...\pester\Pester.psm1: line 3171
Run-Test, ...\pester\Pester.psm1: line 1675
Invoke-Test, ...\pester\Pester.psm1: line 2475
Invoke-Pester<End>, ...\pester\Pester.psm1: line 5272
<ScriptBlock>, ...\TaskInvoker.ps1: line 116

Describe your environment

A CI executor which runs multiple instances of Pester in parallel in PowerShell 5.1.

The error does not occur in PowerShell 7.3 and above.

Possible Solution?

Are you happy to accept a PR which modifies the retried operation in New-RandomTempRegistry?

fflaten commented 9 months ago

Thanks for the report. Are you still experiencing this? If so, we'd appreciate a PR.

I hope it's the last one for this mysterious behavior, but we might need this for all read operations in TestRegistry.ps1 as it's a known issue in .NET Framework (fixed in .NET/Core)

chrisdent-de commented 9 months ago

Sorry, just been a bit busy. I'm planning to PR a more extensive retry op around this. In the meantime I've disabled TestRegistry drive so the pressure to fix went off a bit.