@@ -745,53 +745,64 @@ public async Task SendPingToExternalHostWithLowTtlTest()
745
745
Assert . NotEqual ( IPAddress . Any , pingReply . Address ) ;
746
746
}
747
747
748
- [ Fact ]
749
- [ OuterLoop ]
750
- public void Ping_TimedOut_Sync_Success ( )
748
+ private async Task Ping_TimedOut_Core ( Func < Ping , string , Task < PingReply > > sendPing )
751
749
{
752
- var sender = new Ping ( ) ;
753
- PingReply reply = sender . Send ( TestSettings . UnreachableAddress ) ;
750
+ Ping sender = new Ping ( ) ;
751
+ PingReply reply = await sendPing ( sender , TestSettings . UnreachableAddress ) ;
752
+ if ( reply . Status == IPStatus . DestinationNetworkUnreachable )
753
+ {
754
+ // A network middleware has dropped the packed and replied with DestinationNetworkUnreachable. Repeat the PING attempt on another address.
755
+ reply = await sendPing ( sender , TestSettings . UnreachableAddress2 ) ;
756
+ }
757
+
758
+ if ( reply . Status == IPStatus . DestinationNetworkUnreachable )
759
+ {
760
+ // Do yet another attempt.
761
+ reply = await sendPing ( sender , TestSettings . UnreachableAddress3 ) ;
762
+ }
763
+
754
764
Assert . Equal ( IPStatus . TimedOut , reply . Status ) ;
755
765
}
756
766
757
767
[ Fact ]
758
768
[ OuterLoop ]
759
- public async Task Ping_TimedOut_EAP_Success ( )
760
- {
761
- var sender = new Ping ( ) ;
762
- sender . PingCompleted += ( s , e ) =>
763
- {
764
- var tcs = ( TaskCompletionSource < PingReply > ) e . UserState ;
769
+ public Task Ping_TimedOut_Sync_Success ( )
770
+ => Ping_TimedOut_Core ( ( sender , address ) => Task . Run ( ( ) => sender . Send ( address ) ) ) ;
765
771
766
- if ( e . Cancelled )
767
- {
768
- tcs . TrySetCanceled ( ) ;
769
- }
770
- else if ( e . Error != null )
771
- {
772
- tcs . TrySetException ( e . Error ) ;
773
- }
774
- else
772
+ [ Fact ]
773
+ [ OuterLoop ]
774
+ public Task Ping_TimedOut_EAP_Success ( )
775
+ => Ping_TimedOut_Core ( async ( sender , address ) =>
776
+ {
777
+ static void PingCompleted ( object sender , PingCompletedEventArgs e )
775
778
{
776
- tcs . TrySetResult ( e . Reply ) ;
777
- }
778
- } ;
779
+ var tcs = ( TaskCompletionSource < PingReply > ) e . UserState ;
779
780
780
- var tcs = new TaskCompletionSource < PingReply > ( ) ;
781
- sender . SendAsync ( TestSettings . UnreachableAddress , tcs ) ;
782
-
783
- PingReply reply = await tcs . Task ;
784
- Assert . Equal ( IPStatus . TimedOut , reply . Status ) ;
785
- }
781
+ if ( e . Cancelled )
782
+ {
783
+ tcs . TrySetCanceled ( ) ;
784
+ }
785
+ else if ( e . Error != null )
786
+ {
787
+ tcs . TrySetException ( e . Error ) ;
788
+ }
789
+ else
790
+ {
791
+ tcs . TrySetResult ( e . Reply ) ;
792
+ }
793
+ }
794
+ sender . PingCompleted += PingCompleted ;
795
+ var tcs = new TaskCompletionSource < PingReply > ( ) ;
796
+ sender . SendAsync ( address , tcs ) ;
797
+ PingReply reply = await tcs . Task ;
798
+ sender . PingCompleted -= PingCompleted ;
799
+ return reply ;
800
+ } ) ;
786
801
787
802
[ Fact ]
788
803
[ OuterLoop ]
789
- public async Task Ping_TimedOut_TAP_Success ( )
790
- {
791
- var sender = new Ping ( ) ;
792
- PingReply reply = await sender . SendPingAsync ( TestSettings . UnreachableAddress ) ;
793
- Assert . Equal ( IPStatus . TimedOut , reply . Status ) ;
794
- }
804
+ public Task Ping_TimedOut_TAP_Success ( )
805
+ => Ping_TimedOut_Core ( ( sender , address ) => sender . SendPingAsync ( address ) ) ;
795
806
796
807
private static bool IsRemoteExecutorSupportedAndPrivilegedProcess => RemoteExecutor . IsSupported && PlatformDetection . IsPrivilegedProcess ;
797
808
0 commit comments