From 1c5128ecbd53458440e9fadde4022123beb8cb79 Mon Sep 17 00:00:00 2001 From: Radek Zikmund Date: Thu, 19 Mar 2026 14:45:41 +0100 Subject: [PATCH] Increase TTL in SendPingWithLowTtl_RoundtripTimeIsNonZero to fix macOS flakiness The test was consistently failing on macOS (both osx.15.amd64 and osx.26.arm64) because the first-hop router responds to TTL=1 pings in <1ms, and the raw socket implementation truncates sub-millisecond RTT to 0 via (long) cast. Using TTL=5 allows the packet to travel further, increasing the chance of a measurable (>0ms) round-trip time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../System.Net.Ping/tests/FunctionalTests/PingTest.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs b/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs index 900302a3fa9517..424ec3e7caeb91 100644 --- a/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs +++ b/src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs @@ -822,7 +822,10 @@ public async Task SendPingWithLowTtl_RoundtripTimeIsNonZero() // RTT can legitimately be 0ms on very fast networks, so retry a few times // and assert that at least one reply reports a non-zero RTT. - options.Ttl = 1; + // Use TTL=5 instead of 1 to increase the chance of a measurable (>0ms) round-trip + // time. On macOS, the raw socket implementation truncates sub-millisecond RTT to 0, + // and the first-hop router often responds in <1ms. + options.Ttl = 5; bool gotNonZeroRtt = false; for (int attempt = 0; attempt < 3; attempt++) {