2018-11-15 21:50:04 +01:00
|
|
|
# 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" {
|
2020-01-13 20:34:38 +01:00
|
|
|
(Get-PSHostProcessInfo).ProcessId | Should -Contain $PID
|
2018-11-15 21:50:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 }
|
2019-05-02 02:03:43 +02:00
|
|
|
} | Should -BeTrue
|
2018-11-15 21:50:04 +01:00
|
|
|
$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 }
|
2019-05-02 02:03:43 +02:00
|
|
|
} | Should -BeTrue
|
2018-11-15 21:50:04 +01:00
|
|
|
$psProcess = Get-PSHostProcessInfo | Where-Object { $_.ProcessName -eq "powershell" }
|
|
|
|
$psProcess.Count | Should -BeGreaterOrEqual 1
|
|
|
|
$psProcess.ProcessId | Should -Contain $powershell.id
|
|
|
|
}
|
|
|
|
}
|