From 7d003f4f6743bd6bb56af63897ef11b86b1b659d Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Wed, 31 Jan 2018 22:26:05 -0600 Subject: [PATCH] Change Web Cmdlet Tests to Use 127.0.0.1 not Localhost (#6069) Change Web Cmdlets Tests to Use 127.0.0.1 instead of localhost due to dotnet/corefx#24104 This provides a decent speed boost to the WebCmdlet tests (Faster in dozens of times). --- .../WebCmdlets.Tests.ps1 | 12 ++++++------ test/tools/Modules/WebListener/WebListener.psm1 | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 05356b2edf..d9c62aa13b 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -496,15 +496,15 @@ Describe "Invoke-WebRequest tests" -Tags "Feature" { It "Validate Invoke-WebRequest error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' - $command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2" + $command = "Invoke-WebRequest -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" $result = ExecuteWebCommand -command $command $result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeWebRequestCommand" } $testCase = @( - @{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' } - @{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'http_proxy'; protocol = 'http' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'https_proxy'; protocol = 'https' } ) It "Validate Invoke-WebRequest error with -Proxy option set - ''" -TestCases $testCase { @@ -1632,15 +1632,15 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { It "Validate Invoke-RestMethod error with -Proxy and -NoProxy option" { $uri = Get-WebListenerUrl -Test 'Delay' -TestValue '10' - $command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://localhost:8080' -NoProxy -TimeoutSec 2" + $command = "Invoke-RestMethod -Uri '$uri' -Proxy 'http://127.0.0.1:8080' -NoProxy -TimeoutSec 2" $result = ExecuteWebCommand -command $command $result.Error.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeRestMethodCommand" } $testCase = @( - @{ proxy_address = "http://localhost:9"; name = 'http_proxy'; protocol = 'http' } - @{ proxy_address = "http://localhost:9"; name = 'https_proxy'; protocol = 'https' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'http_proxy'; protocol = 'http' } + @{ proxy_address = "http://127.0.0.1:9"; name = 'https_proxy'; protocol = 'https' } ) It "Validate Invoke-RestMethod error with -Proxy option - ''" -TestCases $testCase { diff --git a/test/tools/Modules/WebListener/WebListener.psm1 b/test/tools/Modules/WebListener/WebListener.psm1 index 26ede1a956..54aed0c665 100644 --- a/test/tools/Modules/WebListener/WebListener.psm1 +++ b/test/tools/Modules/WebListener/WebListener.psm1 @@ -174,7 +174,8 @@ function Get-WebListenerUrl { return $null } $Uri = [System.UriBuilder]::new() - $Uri.Host = 'localhost' + # Use 127.0.0.1 and not localhost due to https://github.com/dotnet/corefx/issues/24104 + $Uri.Host = '127.0.0.1' $Uri.Port = $runningListener.HttpPort $Uri.Scheme = 'Http'