From 17ebbf5efa9a383b465015d85112c2336da6d3b3 Mon Sep 17 00:00:00 2001 From: James Truher Date: Tue, 18 Sep 2018 15:29:58 -0700 Subject: [PATCH 1/2] Test changes needed for running in a container --- .../Test-Connection.Tests.ps1 | 48 +++++++++++-------- .../Invoke-Item.Tests.ps1 | 3 +- .../Help/HelpSystem.OnlineHelp.Tests.ps1 | 3 +- .../ParameterBinding.Tests.ps1 | 6 ++- 4 files changed, 37 insertions(+), 23 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 c97b164c04d..40b895f5895 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 @@ -19,8 +19,13 @@ Describe "Test-Connection" -tags "CI" { # $targetAddressIPv6 = "::1" $targetAddressIPv6 = [System.Net.Dns]::GetHostEntry($targetName).AddressList[0].IPAddressToString $UnreachableAddress = "10.11.12.13" - $realName = "google-public-dns-a.google.com" - $realAddress = [System.Net.Dns]::GetHostEntry($realName).AddressList[0].IPAddressToString + # this resolves to an actual IP raher than 127.0.0.1 + # this can also include both IPv4 and IPv6, so select InterNetwork rather than InternNetworkV6 + $realAddress = [System.Net.Dns]::GetHostEntry($hostName).AddressList | + ?{$_.AddressFamily -eq "InterNetwork"} | + Select-Object -First 1 | + %{ $_.IPAddressToString } + $realName = [System.Net.Dns]::GetHostEntry($realAddress).HostName $jobContinues = Start-Job { Test-Connection $using:targetAddress -Continues } } @@ -79,26 +84,28 @@ Describe "Test-Connection" -tags "CI" { } # In VSTS, address is 0.0.0.0 - It "Force IPv4 with implicit PingOptions" -Skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) { - $result = Test-Connection $realName -Count 1 -IPv4 + It "Force IPv4 with implicit PingOptions" { + $result = Test-Connection $hostName -Count 1 -IPv4 $result.Replies[0].Address | Should -BeExactly $realAddress - $result.Replies[0].Options.Ttl | Should -BeLessThan 128 + $result.Replies[0].Options.Ttl | Should -BeLessOrEqual 128 if ($isWindows) { $result.Replies[0].Options.DontFragment | Should -BeFalse } } # In VSTS, address is 0.0.0.0 - It "Force IPv4 with explicit PingOptions" -Skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) { - $result1 = Test-Connection $realName -Count 1 -IPv4 -MaxHops 10 -DontFragment + It "Force IPv4 with explicit PingOptions" { + $result1 = Test-Connection $hostName -Count 1 -IPv4 -MaxHops 10 -DontFragment - $result2 = Test-Connection $realName -Count 1 -IPv4 -MaxHops 1 -DontFragment + # explicitly go to google dns. this test will pass even in the destination is unreachable + # it's more about breaking out of the loop + $result2 = Test-Connection 8.8.8.8 -Count 1 -IPv4 -MaxHops 1 -DontFragment $result1.Replies[0].Address | Should -BeExactly $realAddress # .Net Core (.Net Framework) returns Options based on default PingOptions() constructor (Ttl=128, DontFragment = false). # After .Net Core fix we should have 'DontFragment | Should -Be $true' here. - $result1.Replies[0].Options.Ttl | Should -BeLessThan 128 + $result1.Replies[0].Options.Ttl | Should -BeLessOrEqual 128 if (!$isWindows) { $result1.Replies[0].Options.DontFragment | Should -BeNullOrEmpty $result2.Replies[0].Status | Should -BeExactly "Success" @@ -198,17 +205,17 @@ Describe "Test-Connection" -tags "CI" { # TODO: We skip the MTUSizeDetect tests on Unix because we expect 'TtlExpired' but get 'TimeOut' internally from .Net Core # Skipping on VSTS in Windows due to `TimedOut` Context "MTUSizeDetect" { - It "MTUSizeDetect works" -Pending:(!$isWindows -or (Test-IsVstsWindows)) { - $result = Test-Connection $realName -MTUSizeDetect + It "MTUSizeDetect works" -Pending:(!$isWindows) { + $result = Test-Connection $hostName -MTUSizeDetect $result | Should -BeOfType "System.Net.NetworkInformation.PingReply" - $result.Destination | Should -BeExactly $realName + $result.Destination | Should -BeExactly $hostName $result.Status | Should -BeExactly "Success" $result.MTUSize | Should -BeGreaterThan 0 } - It "Quiet works" -Pending:(!$isWindows -or (Test-IsVstsWindows)) { - $result = Test-Connection $realName -MTUSizeDetect -Quiet + It "Quiet works" -Pending:(!$isWindows) { + $result = Test-Connection $hostName -MTUSizeDetect -Quiet $result | Should -BeOfType "Int32" $result | Should -BeGreaterThan 0 @@ -217,8 +224,9 @@ Describe "Test-Connection" -tags "CI" { Context "TraceRoute" { # Hangs in VSTS Linux - It "TraceRoute works" -skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) { - $result = Test-Connection $realName -TraceRoute + It "TraceRoute works" { + # real address is an ipv4 address, so force IPv4 + $result = Test-Connection $hostName -TraceRoute -IPv4 $replies = $result.Replies # Check target host reply. $pingReplies = $replies[-1].PingReplies @@ -227,7 +235,7 @@ Describe "Test-Connection" -tags "CI" { $result | Should -BeOfType "Microsoft.PowerShell.Commands.TestConnectionCommand+TraceRouteResult" $result.Source | Should -BeExactly $hostName $result.DestinationAddress | Should -BeExactly $realAddress - $result.DestinationHost | Should -BeExactly $realName + $result.DestinationHost | Should -BeExactly $hostName $replies.Count | Should -BeGreaterThan 0 $replies[0] | Should -BeOfType "Microsoft.PowerShell.Commands.TestConnectionCommand+TraceRouteReply" @@ -237,15 +245,15 @@ Describe "Test-Connection" -tags "CI" { $pingReplies[0].Address | Should -BeExactly $realAddress $pingReplies[0].Status | Should -BeExactly "Success" if (!$isWindows) { - $pingReplies[0].Buffer.Count | Should -Be 0 + $pingReplies[0].Buffer.Count | Should -Match '^0$|^32$' } else { $pingReplies[0].Buffer.Count | Should -Be 32 } } # Hangs in VSTS Linux - It "Quiet works" -skip:((Test-IsVstsLinux) -or (Test-IsVstsWindows)) { - $result = Test-Connection $realName -TraceRoute -Quiet + It "Quiet works" { + $result = Test-Connection $hostName -TraceRoute -Quiet 6>$null $result | Should -BeTrue } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 index b45132e9a3e..45ec634ffda 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Invoke-Item.Tests.ps1 @@ -77,8 +77,9 @@ Describe "Invoke-Item basic tests" -Tags "Feature" { } else { ## On Unix, we use `UseShellExecute = false` ## 'ping' on Unix write out usage to stderr + ## some ping show 'usage: ping' and others show 'ping:' & $powershell -noprofile -c "Invoke-Item '$ping'" 2> $redirectFile - Get-Content $redirectFile -Raw | Should -Match "usage: ping" + Get-Content $redirectFile -Raw | Should -Match "usage: ping|ping:" } } diff --git a/test/powershell/engine/Help/HelpSystem.OnlineHelp.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.OnlineHelp.Tests.ps1 index c14ef99ff04..f4c001499d2 100644 --- a/test/powershell/engine/Help/HelpSystem.OnlineHelp.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.OnlineHelp.Tests.ps1 @@ -48,7 +48,8 @@ Describe 'Online help tests for PowerShell Core Cmdlets' -Tags "CI" { Describe 'Get-Help -Online opens the default web browser and navigates to the cmdlet help content' -Tags "Feature" { $skipTest = [System.Management.Automation.Platform]::IsIoT -or - [System.Management.Automation.Platform]::IsNanoServer + [System.Management.Automation.Platform]::IsNanoServer -or + $env:__InContainer -eq 1 # this code is a workaround for issue: https://github.com/PowerShell/PowerShell/issues/3079 if((-not ($skipTest)) -and $IsWindows) diff --git a/test/powershell/engine/ParameterBinding/ParameterBinding.Tests.ps1 b/test/powershell/engine/ParameterBinding/ParameterBinding.Tests.ps1 index 975a8b96510..a3a51831e41 100644 --- a/test/powershell/engine/ParameterBinding/ParameterBinding.Tests.ps1 +++ b/test/powershell/engine/ParameterBinding/ParameterBinding.Tests.ps1 @@ -333,7 +333,7 @@ Describe "Parameter Binding Tests" -Tags "CI" { $dllPath = Join-Path $tempDir TestBindingCmdlet.dll - Add-Type -OutputAssembly $dllPath -TypeDefinition ' + $typeDefinition = ' using System; using System.Management.Automation; @@ -354,6 +354,10 @@ Describe "Parameter Binding Tests" -Tags "CI" { } } ' + if ( !(Test-Path $dllPath)) + { + Add-Type -OutputAssembly $dllPath -TypeDefinition $typeDefinition + } Import-Module $dllPath } From c7d0f7ae83bd87ae1170210d471f28c8439f4aeb Mon Sep 17 00:00:00 2001 From: James Truher Date: Thu, 27 Sep 2018 10:46:21 -0700 Subject: [PATCH 2/2] [feature] Fix a number of typos make the `MTUSizeDetect` tests pending for MacOS only. --- .../Test-Connection.Tests.ps1 | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 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 40b895f5895..2d9806de4a1 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Test-Connection.Tests.ps1 @@ -19,13 +19,14 @@ Describe "Test-Connection" -tags "CI" { # $targetAddressIPv6 = "::1" $targetAddressIPv6 = [System.Net.Dns]::GetHostEntry($targetName).AddressList[0].IPAddressToString $UnreachableAddress = "10.11.12.13" - # this resolves to an actual IP raher than 127.0.0.1 - # this can also include both IPv4 and IPv6, so select InterNetwork rather than InternNetworkV6 + # this resolves to an actual IP rather than 127.0.0.1 + # this can also include both IPv4 and IPv6, so select InterNetwork rather than InterNetworkV6 $realAddress = [System.Net.Dns]::GetHostEntry($hostName).AddressList | - ?{$_.AddressFamily -eq "InterNetwork"} | + Where-Object {$_.AddressFamily -eq "InterNetwork"} | Select-Object -First 1 | - %{ $_.IPAddressToString } - $realName = [System.Net.Dns]::GetHostEntry($realAddress).HostName + Foreach-Object {$_.IPAddressToString} + # under some environments, we can't round trip this and retrieve the real name from the address + # in this case we will simply use the hostname $jobContinues = Start-Job { Test-Connection $using:targetAddress -Continues } } @@ -98,7 +99,7 @@ Describe "Test-Connection" -tags "CI" { It "Force IPv4 with explicit PingOptions" { $result1 = Test-Connection $hostName -Count 1 -IPv4 -MaxHops 10 -DontFragment - # explicitly go to google dns. this test will pass even in the destination is unreachable + # explicitly go to google dns. this test will pass even if the destination is unreachable # it's more about breaking out of the loop $result2 = Test-Connection 8.8.8.8 -Count 1 -IPv4 -MaxHops 1 -DontFragment @@ -108,7 +109,8 @@ Describe "Test-Connection" -tags "CI" { $result1.Replies[0].Options.Ttl | Should -BeLessOrEqual 128 if (!$isWindows) { $result1.Replies[0].Options.DontFragment | Should -BeNullOrEmpty - $result2.Replies[0].Status | Should -BeExactly "Success" + # depending on the network configuration any of the following should be returned + $result2.Replies[0].Status | Should -BeIn "TtlExpired","TimedOut","Success" } else { $result1.Replies[0].Options.DontFragment | Should -BeFalse # We expect 'TtlExpired' but if a router don't reply we get `TimeOut` @@ -203,9 +205,8 @@ Describe "Test-Connection" -tags "CI" { } # TODO: We skip the MTUSizeDetect tests on Unix because we expect 'TtlExpired' but get 'TimeOut' internally from .Net Core - # Skipping on VSTS in Windows due to `TimedOut` Context "MTUSizeDetect" { - It "MTUSizeDetect works" -Pending:(!$isWindows) { + It "MTUSizeDetect works" -pending:($IsMacOS) { $result = Test-Connection $hostName -MTUSizeDetect $result | Should -BeOfType "System.Net.NetworkInformation.PingReply" @@ -214,7 +215,7 @@ Describe "Test-Connection" -tags "CI" { $result.MTUSize | Should -BeGreaterThan 0 } - It "Quiet works" -Pending:(!$isWindows) { + It "Quiet works" -pending:($IsMacOS) { $result = Test-Connection $hostName -MTUSizeDetect -Quiet $result | Should -BeOfType "Int32" @@ -223,7 +224,6 @@ Describe "Test-Connection" -tags "CI" { } Context "TraceRoute" { - # Hangs in VSTS Linux It "TraceRoute works" { # real address is an ipv4 address, so force IPv4 $result = Test-Connection $hostName -TraceRoute -IPv4 @@ -251,7 +251,6 @@ Describe "Test-Connection" -tags "CI" { } } - # Hangs in VSTS Linux It "Quiet works" { $result = Test-Connection $hostName -TraceRoute -Quiet 6>$null