mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Clean up the IPC named pipe on PowerShell exit (#12187)
This commit is contained in:
@@ -53,4 +53,49 @@ Describe "Get-PSHostProcessInfo tests" -Tag CI {
|
||||
$psProcess.Count | Should -BeGreaterOrEqual 1
|
||||
$psProcess.ProcessId | Should -Contain $powershell.id
|
||||
}
|
||||
|
||||
It "Verifies named pipe filepath get method" {
|
||||
$pipeFilePath = (Get-PSHostProcessInfo -Id $pid).GetPipeNameFilePath()
|
||||
$pipeFilePath | Should -Exist
|
||||
}
|
||||
|
||||
It "Verifies named pipe filepath is removed on process exit" {
|
||||
$aliveFile = Join-Path -Path $TestDrive -ChildPath 'AliveFileXXZZ.txt'
|
||||
"" | Out-File -FilePath $aliveFile
|
||||
$testfilePath = Join-Path -Path $TestDrive -ChildPath 'TestScriptXXZZ.ps1'
|
||||
@'
|
||||
param (
|
||||
[string] $LiveFilePath
|
||||
)
|
||||
|
||||
$count = 0
|
||||
while ((Test-Path -Path $LiveFilePath) -and ($count++ -lt 60))
|
||||
{
|
||||
Start-Sleep -Milliseconds 500
|
||||
}
|
||||
|
||||
exit
|
||||
'@ | Out-File -FilePath $testfilePath
|
||||
|
||||
# Create PowerShell process to monitor.
|
||||
$psFileName = $IsWindows ? 'pwsh.exe' : 'pwsh'
|
||||
$psPath = Join-Path -Path $PSHOME -ChildPath $psFileName
|
||||
$psProc = Start-Process -FilePath $psPath -ArgumentList "-File $testfilePath -LiveFilePath $aliveFile" -PassThru
|
||||
Wait-UntilTrue -sb {
|
||||
(Get-PSHostProcessInfo -Id $psProc.Id) -ne $null
|
||||
} -TimeoutInMilliseconds 5000 -IntervalInMilliseconds 250
|
||||
|
||||
# Verify named pipe file path.
|
||||
$psNamedPipePath = (Get-PSHostProcessInfo -Id $psProc.Id).GetPipeNameFilePath()
|
||||
$psNamedPipePath | Should -Exist
|
||||
|
||||
# Signal PowerShell test process to exit normally.
|
||||
Remove-Item -Path $aliveFile -Force -ErrorAction Ignore
|
||||
Wait-UntilTrue -sb {
|
||||
(Test-Path -Path $psNamedPipePath) -eq $false
|
||||
} -TimeoutInMilliseconds 5000 -IntervalInMilliseconds 250
|
||||
|
||||
# Verify named pipe file path is removed.
|
||||
$psNamedPipePath | Should -Not -Exist
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user