Clean up the IPC named pipe on PowerShell exit (#12187)

This commit is contained in:
Paul Higinbotham
2020-03-26 09:47:33 -07:00
committed by GitHub
parent 238cb5c8dc
commit 668d72c4af
3 changed files with 110 additions and 29 deletions
@@ -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
}
}