From 48db3de03ed427f10646f1fbb824a2b4eb958378 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 16 Oct 2019 09:55:41 -0700 Subject: [PATCH] Make the event handler leaking test stable (#10790) --- build.psm1 | 13 +++++++------ test/xUnit/csharp/test_SecuritySupport.cs | 21 ++++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/build.psm1 b/build.psm1 index 79bcccc6ce..5a9aa3f189 100644 --- a/build.psm1 +++ b/build.psm1 @@ -390,11 +390,10 @@ Fix steps: } try { + # Relative paths do not work well if cwd is not changed to project + Push-Location $Options.Top if ($Options.Runtime -notlike 'fxdependent*') { - # Relative paths do not work well if cwd is not changed to project - Push-Location $Options.Top - if ($Options.Runtime -like 'win-arm*') { $Arguments += "/property:SDKToUse=Microsoft.NET.Sdk" } else { @@ -410,7 +409,6 @@ Fix steps: Start-CrossGen -PublishPath $publishPath -Runtime $script:Options.Runtime Write-Log "pwsh.exe with ngen binaries is available at: $($Options.Output)" } - } else { $globalToolSrcFolder = Resolve-Path (Join-Path $Options.Top "../Microsoft.PowerShell.GlobalTool.Shim") | Select-Object -ExpandProperty Path @@ -420,8 +418,6 @@ Fix steps: $Arguments += "/property:SDKToUse=Microsoft.NET.Sdk.WindowsDesktop" } - # Relative paths do not work well if cwd is not changed to project - Push-Location $Options.Top Write-Log "Run dotnet $Arguments from $pwd" Start-NativeExecution { dotnet $Arguments } Write-Log "PowerShell output: $($Options.Output)" @@ -440,6 +436,11 @@ Fix steps: Pop-Location } + # No extra post-building task will run if '-SMAOnly' is specified, because its purpose is for a quick update of S.M.A.dll after full build. + if ($SMAOnly) { + return + } + # publish reference assemblies try { Push-Location "$PSScriptRoot/src/TypeCatalogGen" diff --git a/test/xUnit/csharp/test_SecuritySupport.cs b/test/xUnit/csharp/test_SecuritySupport.cs index 6090b0d1ee..0d7cbbc8f0 100644 --- a/test/xUnit/csharp/test_SecuritySupport.cs +++ b/test/xUnit/csharp/test_SecuritySupport.cs @@ -12,19 +12,14 @@ namespace PSTests.Parallel [Fact] public static void TestScanContent() { - Assert.Equal(AmsiUtils.AmsiNativeMethods.AMSI_RESULT.AMSI_RESULT_NOT_DETECTED, AmsiUtils.ScanContent(string.Empty, string.Empty)); - } - - [Fact] - public static void TestCloseSession() - { - AmsiUtils.CloseSession(); - } - - [Fact] - public static void TestUninitialize() - { - AmsiUtils.Uninitialize(); + try + { + Assert.Equal(AmsiUtils.AmsiNativeMethods.AMSI_RESULT.AMSI_RESULT_NOT_DETECTED, AmsiUtils.ScanContent(string.Empty, string.Empty)); + } + finally + { + AmsiUtils.Uninitialize(); + } } } }