From ee5fc080e23ea366c1555a2e49fa7afcb4cde418 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 11 Dec 2018 14:15:33 -0800 Subject: [PATCH] Remove `dotnet` dependency to start WebListener (#8390) WebListener.exe (which was already being built) is sufficient to start web listener. Remove the dependency on `dotnet` being present to start the web listener. Use `Start-Process` instead of `Start-Job` to launch the WebListener. --- .../Test-Connection.Tests.ps1 | 23 ++++++++++--------- .../WebCmdlets.Tests.ps1 | 8 +++---- .../Modules/WebListener/WebListener.psm1 | 12 +++++----- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 index 8a5cda3e58..d5347790c1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 @@ -257,19 +257,20 @@ Describe "Test-Connection" -tags "CI" { $result | Should -BeTrue } } +} - Context "Connection" { - BeforeAll { - # Ensure the local host listen on port 80 - $WebListener = Start-WebListener - } +Describe "Connection" -Tag "CI", "RequireAdminOnWindows" { + BeforeAll { + # Ensure the local host listen on port 80 + $WebListener = Start-WebListener + $UnreachableAddress = "10.11.12.13" + } - It "Test connection to local host port 80" { - Test-Connection '127.0.0.1' -TCPPort $WebListener.HttpPort | Should -BeTrue - } + It "Test connection to local host port 80" { + Test-Connection '127.0.0.1' -TCPPort $WebListener.HttpPort | Should -BeTrue + } - It "Test connection to unreachable host port 80" { - Test-Connection $UnreachableAddress -TCPPort 80 -TimeOut 1 | Should -BeFalse - } + It "Test connection to unreachable host port 80" { + Test-Connection $UnreachableAddress -TCPPort 80 -TimeOut 1 | Should -BeFalse } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index d614ebbab6..d57ad4e9f1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -367,7 +367,7 @@ $redirectTests = @( @{redirectType = 'relative'; redirectedMethod = 'GET'} ) -Describe "Invoke-WebRequest tests" -Tags "Feature" { +Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" { BeforeAll { $WebListener = Start-WebListener } @@ -1785,7 +1785,7 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { } } -Describe "Invoke-RestMethod tests" -Tags "Feature" { +Describe "Invoke-RestMethod tests" -Tags "Feature", "RequireAdminOnWindows" { BeforeAll { $WebListener = Start-WebListener } @@ -3069,7 +3069,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { } } -Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Feature" { +Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Feature", "RequireAdminOnWindows" { BeforeAll { $WebListener = Start-WebListener } @@ -3149,7 +3149,7 @@ Describe "Validate Invoke-WebRequest and Invoke-RestMethod -InFile" -Tags "Featu } } -Describe "Web cmdlets tests using the cmdlet's aliases" -Tags "CI" { +Describe "Web cmdlets tests using the cmdlet's aliases" -Tags "CI", "RequireAdminOnWindows" { BeforeAll { $WebListener = Start-WebListener } diff --git a/test/tools/Modules/WebListener/WebListener.psm1 b/test/tools/Modules/WebListener/WebListener.psm1 index d400c768ef..223cbcc561 100644 --- a/test/tools/Modules/WebListener/WebListener.psm1 +++ b/test/tools/Modules/WebListener/WebListener.psm1 @@ -120,7 +120,7 @@ function Start-WebListener } $initTimeoutSeconds = 15 - $appDll = 'WebListener.dll' + $appExe = (get-command WebListener).Path $serverPfx = 'ServerCert.pfx' $serverPfxPassword = New-RandomHexString $clientPfx = 'ClientCert.pfx' @@ -136,7 +136,7 @@ function Start-WebListener $Job = Start-Job { $path = Split-Path -parent (get-command WebListener).Path -Verbose Push-Location $path -Verbose - 'appDLL: {0}' -f $using:appDll + 'appEXE: {0}' -f $using:appExe 'serverPfxPath: {0}' -f $using:serverPfxPath 'serverPfxPassword: {0}' -f $using:serverPfxPassword 'HttpPort: {0}' -f $using:HttpPort @@ -144,14 +144,15 @@ function Start-WebListener 'Tls11Port: {0}' -f $using:Tls11Port 'TlsPort: {0}' -f $using:TlsPort $env:ASPNETCORE_ENVIRONMENT = 'Development' - dotnet $using:appDll $using:serverPfxPath $using:serverPfxPassword $using:HttpPort $using:HttpsPort $using:Tls11Port $using:TlsPort + & $using:appExe $using:serverPfxPath $using:serverPfxPassword $using:HttpPort $using:HttpsPort $using:Tls11Port $using:TlsPort } + $Script:WebListener = [WebListener]@{ HttpPort = $HttpPort HttpsPort = $HttpsPort Tls11Port = $Tls11Port TlsPort = $TlsPort - Job = $Job + Job = $Job } # Count iterations of $sleepMilliseconds instead of using system time to work around possible CI VM sleep/delays @@ -172,8 +173,7 @@ function Start-WebListener $jobVerbose = $Job.ChildJobs[0].Verbose | Out-String $Job | Stop-Job $Job | Remove-Job -Force - $message = 'WebListener did not start before the timeout was reached.{0}Errors:{0}{1}{0}Output:{0}{2}{0}Verbose:{0}{3}' -f - ([System.Environment]::NewLine), $jobErrors, $jobOutput, $jobVerbose + $message = 'WebListener did not start before the timeout was reached.{0}Errors:{0}{1}{0}Output:{0}{2}{0}Verbose:{0}{3}' -f ([System.Environment]::NewLine), $jobErrors, $jobOutput, $jobVerbose throw $message } return $Script:WebListener