Files
PowerShell-PowerShell/test/powershell/Modules/Microsoft.PowerShell.Core/Get-PSHostProcessInfo.Tests.ps1
T
Steve Lee c5dd3bd2c9 Support 'Get-PSHostProcessInfo' and 'Enter-PSHostProcess' on Unix platforms (#8232)
There a some differences in support of named pipes for Windows and non-Windows.  Named pipes on Unix have a 104 character path limit.  On macOS, the `$env:TMPDIR` (on my system) is already 49 characters; corefx adds 12 more.  Since AppDomainName isn't really used, changed it from `DefaultAppDomain` to `None` to shorten the name.  Need to keep it since Windows PowerShell expects it.  Changed `starttime` part of pipe name to 8 hex characters which is to provide uniqueness to the pipe name.
2018-11-15 12:50:04 -08:00

52 lines
1.6 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "Get-PSHostProcessInfo tests" -Tag CI {
BeforeAll {
$si = [System.Diagnostics.ProcessStartInfo]::new()
$si.FileName = "pwsh"
$si.Arguments = "-noexit"
$si.RedirectStandardInput = $true
$si.RedirectStandardOutput = $true
$si.RedirectStandardError = $true
$pwsh = [System.Diagnostics.Process]::Start($si)
if ($IsWindows) {
$si.FileName = "powershell"
$powershell = [System.Diagnostics.Process]::Start($si)
}
}
AfterAll {
$pwsh | Stop-Process
if ($IsWindows) {
$powershell | Stop-Process
}
}
It "Should return own self" {
(Get-PSHostProcessInfo).ProcessId | Should -Contain $pid
}
It "Should list info for other PowerShell hosted processes" {
# Creation of the named pipe is async
Wait-UntilTrue {
Get-PSHostProcessInfo | Where-Object { $_.ProcessId -eq $pwsh.Id }
}
$pshosts = Get-PSHostProcessInfo
$pshosts.Count | Should -BeGreaterOrEqual 1
$pshosts.ProcessId | Should -Contain $pwsh.Id
}
It "Should list Windows PowerShell process" -Skip:(!$IsWindows) {
# Creation of the named pipe is async
Wait-UntilTrue {
Get-PSHostProcessInfo | Where-Object { $_.ProcessId -eq $powershell.Id }
}
$psProcess = Get-PSHostProcessInfo | Where-Object { $_.ProcessName -eq "powershell" }
$psProcess.Count | Should -BeGreaterOrEqual 1
$psProcess.ProcessId | Should -Contain $powershell.id
}
}