-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Remove dependency on DNS for Test-Connection tests on macOS
#12943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TravisEz13
merged 19 commits into
PowerShell:master
from
rjmholt:improve-test-connection-tests
Jun 16, 2020
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8b16073
Add ifconfig fallback for Test-Connection tests on macOS
rjmholt c5bd701
Add more hostname resolution information
rjmholt baecb7f
Attempt to display errors
rjmholt ffb070e
Try alternate format output
rjmholt 5ad31d8
Try hostname | nslookup
rjmholt 035ef47
Add nslookup test
rjmholt 97e6858
Fix stupid test
rjmholt 296d6a2
Attempt to use Gateway address instead
rjmholt d4cfaeb
Fix up hostname uses
rjmholt fb726ad
Use alternate test inputs on macOS
rjmholt 6378d90
Use gateway address where possible
rjmholt 406982c
Fix test expectations
rjmholt d9bee78
Fix test
rjmholt 6a0e1f5
Remove wait-debugger
rjmholt 123f031
Only use gateway address when external host address cannot be resolved
rjmholt d592051
Remove failing assertion, and open #12967
rjmholt f032050
Fix test error
rjmholt defb791
Try using the real address off macOS
rjmholt e662e99
Remove ??
rjmholt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,19 +3,47 @@ | |
|
|
||
| Import-Module HelpersCommon | ||
|
|
||
| function GetGatewayAddress | ||
| { | ||
| return [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | | ||
| Where-Object { $_.OperationalStatus -eq 'Up' -and $_.NetworkInterfaceType -ne 'Loopback' } | | ||
| ForEach-Object { $_.GetIPProperties().GatewayAddresses } | | ||
| Select-Object -First 1 | | ||
| ForEach-Object { $_.Address.IPAddressToString } | ||
| } | ||
|
|
||
| function GetExternalHostAddress([string]$HostName) | ||
| { | ||
| if (-not $HostName) | ||
| { | ||
| return | ||
| } | ||
|
|
||
| try | ||
| { | ||
| return [System.Net.Dns]::GetHostEntry($HostName).AddressList | | ||
| Where-Object { $_.AddressFamily -eq 'InterNetwork' } | | ||
| Select-Object -First 1 | | ||
| ForEach-Object { $_.IPAddressToString } | ||
| } | ||
| catch | ||
| { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| Describe "Test-Connection" -tags "CI" { | ||
| BeforeAll { | ||
| $hostName = [System.Net.Dns]::GetHostName() | ||
| $gatewayAddress = GetGatewayAddress | ||
| $publicHostAddress = GetExternalHostAddress -HostName $hostName | ||
|
|
||
| $testAddress = if ($publicHostAddress) { $publicHostAddress } else { $gatewayAddress } | ||
|
|
||
| $targetName = "localhost" | ||
| $targetAddress = "127.0.0.1" | ||
| $targetAddressIPv6 = "::1" | ||
| $UnreachableAddress = "10.11.12.13" | ||
| # 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 | | ||
| Where-Object { $_.AddressFamily -eq "InterNetwork" } | | ||
| Select-Object -First 1 | | ||
| 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 -Repeat } | ||
|
|
@@ -77,35 +105,35 @@ Describe "Test-Connection" -tags "CI" { | |
| $error[0].Exception.InnerException.ErrorCode | Should -Be $code | ||
| } | ||
|
|
||
| # In VSTS, address is 0.0.0.0. Making pending due to instability in Az DevOps. | ||
| It "Force IPv4 with implicit PingOptions" -Pending:($IsMacOS) { | ||
| $result = Test-Connection $hostName -Count 1 -IPv4 | ||
| It "Force IPv4 with implicit PingOptions" { | ||
| $result = Test-Connection $testAddress -Count 1 -IPv4 | ||
|
|
||
| $result[0].Address | Should -BeExactly $realAddress | ||
| $result[0].Address | Should -BeExactly $testAddress | ||
| $result[0].Reply.Options.Ttl | Should -BeLessOrEqual 128 | ||
| if ($IsWindows) { | ||
| $result[0].Reply.Options.DontFragment | Should -BeFalse | ||
| } | ||
| } | ||
|
|
||
| # In VSTS, address is 0.0.0.0 | ||
| # This test is marked as PENDING as .NET Core does not return correct PingOptions from ping request | ||
| It "Force IPv4 with explicit PingOptions" -Pending { | ||
| $result1 = Test-Connection $hostName -Count 1 -IPv4 -MaxHops 10 -DontFragment | ||
| It "Force IPv4 with explicit PingOptions" { | ||
| $result1 = Test-Connection $testAddress -Count 1 -IPv4 -MaxHops 10 -DontFragment | ||
|
|
||
| # 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 | ||
|
|
||
| $result1.Address | Should -BeExactly $realAddress | ||
| $result1.Address | Should -BeExactly $testAddress | ||
| $result1.Reply.Options.Ttl | Should -BeLessOrEqual 128 | ||
|
|
||
| if (!$IsWindows) { | ||
| $result1.Reply.Options.DontFragment | Should -BeFalse | ||
| # Depending on the network configuration any of the following should be returned | ||
| $result2.Status | Should -BeIn "TtlExpired", "TimedOut", "Success" | ||
| } else { | ||
| $result1.Reply.Options.DontFragment | Should -BeTrue | ||
| # This assertion currently fails, see https://github.com/PowerShell/PowerShell/issues/12967 | ||
| #$result1.Reply.Options.DontFragment | Should -BeTrue | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened #12967 for this |
||
|
|
||
| # We expect 'TtlExpired' but if a router don't reply we get `TimedOut` | ||
| # AzPipelines returns $null | ||
| $result2.Status | Should -BeIn "TtlExpired", "TimedOut", $null | ||
|
|
@@ -232,34 +260,33 @@ Describe "Test-Connection" -tags "CI" { | |
| # We skip the MtuSize detection tests when in containers, as the environments throw raw exceptions | ||
| # instead of returning a PacketTooBig response cleanly. | ||
| It "MTUSizeDetect works" -Pending:($env:__INCONTAINER -eq 1) { | ||
| $result = Test-Connection $hostName -MtuSize | ||
| $result = Test-Connection $testAddress -MtuSize | ||
|
|
||
| $result | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+PingMtuStatus | ||
| $result.Destination | Should -BeExactly $hostName | ||
| $result.Destination | Should -BeExactly $testAddress | ||
| $result.Status | Should -BeExactly "Success" | ||
| $result.MtuSize | Should -BeGreaterThan 0 | ||
| } | ||
|
|
||
| It "Quiet works" -Pending:($env:__INCONTAINER -eq 1) { | ||
| $result = Test-Connection $hostName -MtuSize -Quiet | ||
| $result = Test-Connection $gatewayAddress -MtuSize -Quiet | ||
|
|
||
| $result | Should -BeOfType Int32 | ||
| $result | Should -BeGreaterThan 0 | ||
| } | ||
| } | ||
|
|
||
| Context "TraceRoute" { | ||
| # Mark it as pending due to instability in Az DevOps | ||
| It "TraceRoute works" -Pending:($IsMacOS) { | ||
| It "TraceRoute works" { | ||
| # real address is an ipv4 address, so force IPv4 | ||
| $result = Test-Connection $hostName -TraceRoute -IPv4 | ||
| $result = Test-Connection $testAddress -TraceRoute -IPv4 | ||
|
|
||
| $result[0] | Should -BeOfType Microsoft.PowerShell.Commands.TestConnectionCommand+TraceStatus | ||
| $result[0].Source | Should -BeExactly $hostName | ||
| $result[0].TargetAddress | Should -BeExactly $realAddress | ||
| $result[0].Target | Should -BeExactly $hostName | ||
| $result[0].TargetAddress | Should -BeExactly $testAddress | ||
| $result[0].Target | Should -BeExactly $testAddress | ||
| $result[0].Hop | Should -Be 1 | ||
| $result[0].HopAddress | Should -BeExactly $realAddress | ||
| $result[0].HopAddress.IPAddressToString | Should -BeExactly $testAddress | ||
| $result[0].Status | Should -BeExactly "Success" | ||
| if (!$IsWindows) { | ||
| $result[0].Reply.Buffer.Count | Should -Match '^0$|^32$' | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking, but could have used the null conditional assignment operator here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to port back to 6.2 -- deliberately removed new operators in most recent commit