Skip to content

Commit 84fb871

Browse files
authored
System.Net.Ping: Skip TimeoutIsRespected test if network is unreachable (#58745)
The TestSettings.UnreachableAddress is using 192.0.2.0 which is documented in RFC5735 as a network to be used in docs/example code. On the Android devices in Helix the upstream network is configured to not route this address which results in a "Destination Net Unreachable" response which causes the timeout argument to ping to be ignored and ping returns immediately. Skip the test in these cases. Example output from ping on the device: ``` 1|sunfish:/ $ time ping -c 1 -W 2 -s 50 192.0.2.0 PING 192.0.2.0 (192.0.2.0) 50(78) bytes of data. From 131.107.5.118: icmp_seq=1 Destination Net Unreachable --- 192.0.2.0 ping statistics --- 1 packets transmitted, 0 received, +1 errors, 100% packet loss, time Oms 0m00.03s real 0m00.00s user 0m00.00s system ```
1 parent 8dbf300 commit 84fb871

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libraries/System.Net.Ping/tests/FunctionalTests/UnixPingUtilityTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99

1010
using Xunit;
11+
using Microsoft.DotNet.XUnitExtensions;
1112

1213
namespace System.Net.NetworkInformation.Tests
1314
{
@@ -19,7 +20,7 @@ public class UnixPingUtilityTests
1920
{
2021
private const int IcmpHeaderLengthInBytes = 8;
2122

22-
[Theory]
23+
[ConditionalTheory]
2324
[InlineData(0)]
2425
[InlineData(100)]
2526
[InlineData(1000)]
@@ -32,11 +33,24 @@ public static void TimeoutIsRespected(int timeout)
3233
p.StartInfo.RedirectStandardError = true;
3334
p.StartInfo.RedirectStandardOutput = true;
3435

36+
bool destinationNetUnreachable = false;
37+
p.OutputDataReceived += delegate (object sendingProcess, DataReceivedEventArgs outputLine)
38+
{
39+
if (outputLine.Data?.Contains("Destination Net Unreachable", StringComparison.OrdinalIgnoreCase) == true)
40+
destinationNetUnreachable = true;
41+
};
42+
3543
Stopwatch stopWatch = Stopwatch.StartNew();
3644

3745
p.Start();
46+
p.BeginOutputReadLine();
3847
p.WaitForExit();
3948

49+
if (destinationNetUnreachable)
50+
{
51+
throw new SkipTestException($"Network doesn't route {TestSettings.UnreachableAddress}, skipping test.");
52+
}
53+
4054
//ensure that the process takes longer than or within 10ms of 'timeout', with a 5s maximum
4155
Assert.InRange(stopWatch.ElapsedMilliseconds, timeout - 10, 5000);
4256
}

0 commit comments

Comments
 (0)