-
-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pester throws an exception when run inside runspace #2383
Comments
BTW, just for fun, repro code refactored to use $cpuCount = [Environment]::ProcessorCount
$results = 1..($cpuCount * 2) | ForEach-Object -Parallel {
Import-Module Pester -Force -ErrorAction Stop
$pc = New-PesterConfiguration
$pc.Run.Container = New-PesterContainer -ScriptBlock {Describe 'd' { It 'i' { 1 | Should -Be 1 }}}
$pc.Output.Verbosity = 'None'
$pc.Run.PassThru = $true
$pc.Run.SkipRemainingOnFailure ='Block'
[PSCustomObject]@{
Test = $_
Result = Invoke-Pester -Configuration $pc
}
} -ThrottleLimit $cpuCount
$results The issue is - this is for PowerShell 7+ only. I need parallelization on PowerShell 5.1. Also, @PaulHigin it looks like the |
Did you check if UI is null? Does it work without |
This is very strange:
And as you can see in the right window the |
I have modified the Pester.psm1 once more with simple loop that waits until the And it works now - this is the output of the repro script now: Really strange behavior. I would love if @SeeminglyScience could have a look at it for some thorough explanation. |
@fflaten I was able to chat with @SeeminglyScience yesterday on Discord, and for him it looks like race condition bug (I hope he doesn't mind me posting the conversation screenshot here): I will investigate some more if that's PowerShell or ThreadJob module bug or something else. In the meantime, I'll not use |
This is yet simplest repro case (the number of jobs has to be quite high though to get the repro): 1..500 | % {Start-ThreadJob {1 | Should -BeExactly 1; $supportsVT = $Host.UI.psobject.Properties['SupportsVirtualTerminal'].Value} -StreamingHost $Host -InitializationScript {Import-Module Pester -Force}} | Wait-Job | Receive-Job | Remove-Job -Force |
Thank you for the thorough troubleshooting! This is a weird one and a race-condition sounds right. I was able to reproduce a couple of times then suddenly not, so wasn't able to see if we could make the repro simpler. I doubt module import and calling Either way I support the suggested fix with a few conditions:
Reason being that checking Do you want to provide the PR once the bug report is created by you or Patrick? |
I was able to reproduce the issue without I also think that since this is race condition then checking only I think that for the moment there are 2 options:
elseif ($null -ne $host.UI -and ($hostProperties = $host.UI.psobject.Properties) -and ($supportsVT = $hostProperties['SupportsVirtualTerminal']) -and $supportsVT.Value) { What do you think @fflaten? Ps. I will create an issue in the |
@kborowinski - In your original testing when using Start-ThreadJob I see that you are using the older of the two ThreadJob modules. In my testing in 7.3.6 & 5.1 on So this may be fixed for you using that module (which due to command ordering preferences is being autoloaded over the ThreadJob Module for me) so can you please test this out for me? Also this wasn't tested using Windows Terminal & I am just about to retest there too.
|
@kilasuit Unfortunately the same issue occurs in |
I'm fine with this workaround incl. a comment with link to this issue since I doubt we'll be able to cover this with a test consistently. Thanks for really troubleshooting this and sorry for the delayed response 🙂 . Would you still like to provide a PR? |
No problem, I will provide a PR. |
#2383) (#2472) Co-authored-by: Kris Borowinski <[email protected]>
Checklist
What is the issue?
(This issue was moved from here)
Environment:
Explanation:
I use Pester for advanced infrastructure testing. Due to the long execution time of some tests I need to run them in parallel using
Start-ThreadJob
cmdlet from ThreadJob module. The tests are independent of each other. Sporadically, during initialization, Pester throws an exception:Cannot index into a null array.
The line 13998 in Pester.psm1 module where exceptions happens:
Expected Behavior
Pester should not throw when running in an runspace.
Steps To Reproduce
Start new session:
pwsh -nop
Run following scriptblock:
Output:
Describe your environment
Pester version : 5.5.0 C:\Program Files\WindowsPowerShell\Modules\Pester\5.5.0\Pester.psm1
PowerShell version : 7.3.6
OS version : Microsoft Windows NT 10.0.19045.0
Possible Solution?
Do not use the
-StreamingHost
parameter inStart-ThreadJob
when callingInvoke-Pester
OR:
Replace line 13998 in Pester.psm1 with the following:
The text was updated successfully, but these errors were encountered: