From c4f0d1c893cd7e3eeac04fcccb89cb6edc88cc42 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 15 Nov 2017 09:41:11 -0800 Subject: [PATCH] Add a test for the powershell hang fix (#5451) - Add test for the powershell hang fix - Ignore the 'Sync-PSTags' warning --- build.psm1 | 2 +- .../engine/Api/BasicEngine.Tests.ps1 | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/build.psm1 b/build.psm1 index 6f086e82a8..6677c95b44 100644 --- a/build.psm1 +++ b/build.psm1 @@ -568,7 +568,7 @@ Fix steps: if ($ReleaseTagToUse) { $ReleaseVersion = $ReleaseTagToUse } else { - $ReleaseVersion = (Get-PSCommitId) -replace '^v' + $ReleaseVersion = (Get-PSCommitId -WarningAction SilentlyContinue) -replace '^v' } Start-NativeExecution { & "~/.rcedit/rcedit-x64.exe" "$($Options.Output)" --set-icon "$PSScriptRoot\assets\Powershell_black.ico" ` diff --git a/test/powershell/engine/Api/BasicEngine.Tests.ps1 b/test/powershell/engine/Api/BasicEngine.Tests.ps1 index 16e5d7dd88..00c86e807b 100644 --- a/test/powershell/engine/Api/BasicEngine.Tests.ps1 +++ b/test/powershell/engine/Api/BasicEngine.Tests.ps1 @@ -21,3 +21,27 @@ Describe 'Basic engine APIs' -Tags "CI" { } } } + +Describe "Clean up open Runspaces when exit powershell process" -Tags "Feature" { + It "PowerShell process should not freeze at exit" { + $command = @' +-c $rs = [runspacefactory]::CreateRunspacePool(1,5) +$rs.Open() +$ps = [powershell]::Create() +$ps.RunspacePool = $rs +$null = $ps.AddScript(1).Invoke() +write-host should_not_hang_at_exit +exit +'@ + $process = Start-Process pwsh -ArgumentList $command -PassThru + Wait-UntilTrue -sb { $process.HasExited } -TimeoutInMilliseconds 5000 -IntervalInMilliseconds 1000 > $null + + $expect = "powershell process exits in 5 seconds" + if (-not $process.HasExited) { + Stop-Process -InputObject $process -Force -ErrorAction SilentlyContinue + "powershell process doesn't exit in 5 seconds" | Should Be $expect + } else { + $expect | Should Be $expect + } + } +}