@@ -19,8 +19,14 @@ Describe "Test-Connection" -tags "CI" {
1919 # $targetAddressIPv6 = "::1"
2020 $targetAddressIPv6 = [System.Net.Dns ]::GetHostEntry($targetName ).AddressList[0 ].IPAddressToString
2121 $UnreachableAddress = " 10.11.12.13"
22- $realName = " google-public-dns-a.google.com"
23- $realAddress = [System.Net.Dns ]::GetHostEntry($realName ).AddressList[0 ].IPAddressToString
22+ # this resolves to an actual IP rather than 127.0.0.1
23+ # this can also include both IPv4 and IPv6, so select InterNetwork rather than InterNetworkV6
24+ $realAddress = [System.Net.Dns ]::GetHostEntry($hostName ).AddressList |
25+ Where-Object {$_.AddressFamily -eq " InterNetwork" } |
26+ Select-Object - First 1 |
27+ Foreach-Object {$_.IPAddressToString }
28+ # under some environments, we can't round trip this and retrieve the real name from the address
29+ # in this case we will simply use the hostname
2430 $jobContinues = Start-Job { Test-Connection $using :targetAddress - Continues }
2531 }
2632
@@ -79,29 +85,32 @@ Describe "Test-Connection" -tags "CI" {
7985 }
8086
8187 # In VSTS, address is 0.0.0.0
82- It " Force IPv4 with implicit PingOptions" - Skip:(( Test-IsVstsLinux ) -or ( Test-IsVstsWindows )) {
83- $result = Test-Connection $realName - Count 1 - IPv4
88+ It " Force IPv4 with implicit PingOptions" {
89+ $result = Test-Connection $hostName - Count 1 - IPv4
8490
8591 $result.Replies [0 ].Address | Should - BeExactly $realAddress
86- $result.Replies [0 ].Options.Ttl | Should - BeLessThan 128
92+ $result.Replies [0 ].Options.Ttl | Should - BeLessOrEqual 128
8793 if ($isWindows ) {
8894 $result.Replies [0 ].Options.DontFragment | Should - BeFalse
8995 }
9096 }
9197
9298 # In VSTS, address is 0.0.0.0
93- It " Force IPv4 with explicit PingOptions" - Skip:(( Test-IsVstsLinux ) -or ( Test-IsVstsWindows )) {
94- $result1 = Test-Connection $realName - Count 1 - IPv4 - MaxHops 10 - DontFragment
99+ It " Force IPv4 with explicit PingOptions" {
100+ $result1 = Test-Connection $hostName - Count 1 - IPv4 - MaxHops 10 - DontFragment
95101
96- $result2 = Test-Connection $realName - Count 1 - IPv4 - MaxHops 1 - DontFragment
102+ # explicitly go to google dns. this test will pass even if the destination is unreachable
103+ # it's more about breaking out of the loop
104+ $result2 = Test-Connection 8.8 .8.8 - Count 1 - IPv4 - MaxHops 1 - DontFragment
97105
98106 $result1.Replies [0 ].Address | Should - BeExactly $realAddress
99107 # .Net Core (.Net Framework) returns Options based on default PingOptions() constructor (Ttl=128, DontFragment = false).
100108 # After .Net Core fix we should have 'DontFragment | Should -Be $true' here.
101- $result1.Replies [0 ].Options.Ttl | Should - BeLessThan 128
109+ $result1.Replies [0 ].Options.Ttl | Should - BeLessOrEqual 128
102110 if (! $isWindows ) {
103111 $result1.Replies [0 ].Options.DontFragment | Should - BeNullOrEmpty
104- $result2.Replies [0 ].Status | Should - BeExactly " Success"
112+ # depending on the network configuration any of the following should be returned
113+ $result2.Replies [0 ].Status | Should - BeIn " TtlExpired" , " TimedOut" , " Success"
105114 } else {
106115 $result1.Replies [0 ].Options.DontFragment | Should - BeFalse
107116 # We expect 'TtlExpired' but if a router don't reply we get `TimeOut`
@@ -196,29 +205,28 @@ Describe "Test-Connection" -tags "CI" {
196205}
197206
198207 # TODO: We skip the MTUSizeDetect tests on Unix because we expect 'TtlExpired' but get 'TimeOut' internally from .Net Core
199- # Skipping on VSTS in Windows due to `TimedOut`
200208 Context " MTUSizeDetect" {
201- It " MTUSizeDetect works" - Pending:( ! $isWindows -or ( Test-IsVstsWindows ) ) {
202- $result = Test-Connection $realName - MTUSizeDetect
209+ It " MTUSizeDetect works" - pending:( $IsMacOS ) {
210+ $result = Test-Connection $hostName - MTUSizeDetect
203211
204212 $result | Should - BeOfType " System.Net.NetworkInformation.PingReply"
205- $result.Destination | Should - BeExactly $realName
213+ $result.Destination | Should - BeExactly $hostName
206214 $result.Status | Should - BeExactly " Success"
207215 $result.MTUSize | Should - BeGreaterThan 0
208216 }
209217
210- It " Quiet works" - Pending:( ! $isWindows -or ( Test-IsVstsWindows ) ) {
211- $result = Test-Connection $realName - MTUSizeDetect - Quiet
218+ It " Quiet works" - pending:( $IsMacOS ) {
219+ $result = Test-Connection $hostName - MTUSizeDetect - Quiet
212220
213221 $result | Should - BeOfType " Int32"
214222 $result | Should - BeGreaterThan 0
215223 }
216224 }
217225
218226 Context " TraceRoute" {
219- # Hangs in VSTS Linux
220- It " TraceRoute works " - skip:(( Test-IsVstsLinux ) -or ( Test-IsVstsWindows )) {
221- $result = Test-Connection $realName - TraceRoute
227+ It " TraceRoute works " {
228+ # real address is an ipv4 address, so force IPv4
229+ $result = Test-Connection $hostName - TraceRoute - IPv4
222230 $replies = $result.Replies
223231 # Check target host reply.
224232 $pingReplies = $replies [-1 ].PingReplies
@@ -227,7 +235,7 @@ Describe "Test-Connection" -tags "CI" {
227235 $result | Should - BeOfType " Microsoft.PowerShell.Commands.TestConnectionCommand+TraceRouteResult"
228236 $result.Source | Should - BeExactly $hostName
229237 $result.DestinationAddress | Should - BeExactly $realAddress
230- $result.DestinationHost | Should - BeExactly $realName
238+ $result.DestinationHost | Should - BeExactly $hostName
231239
232240 $replies.Count | Should - BeGreaterThan 0
233241 $replies [0 ] | Should - BeOfType " Microsoft.PowerShell.Commands.TestConnectionCommand+TraceRouteReply"
@@ -237,15 +245,14 @@ Describe "Test-Connection" -tags "CI" {
237245 $pingReplies [0 ].Address | Should - BeExactly $realAddress
238246 $pingReplies [0 ].Status | Should - BeExactly " Success"
239247 if (! $isWindows ) {
240- $pingReplies [0 ].Buffer.Count | Should - Be 0
248+ $pingReplies [0 ].Buffer.Count | Should -Match ' ^0$|^32$ '
241249 } else {
242250 $pingReplies [0 ].Buffer.Count | Should - Be 32
243251 }
244252 }
245253
246- # Hangs in VSTS Linux
247- It " Quiet works" - skip:((Test-IsVstsLinux ) -or (Test-IsVstsWindows )) {
248- $result = Test-Connection $realName - TraceRoute - Quiet
254+ It " Quiet works" {
255+ $result = Test-Connection $hostName - TraceRoute - Quiet 6> $null
249256
250257 $result | Should - BeTrue
251258 }
0 commit comments