Increase TTL in SendPingWithLowTtl_RoundtripTimeIsNonZero to fix macOS flakiness#125774
Increase TTL in SendPingWithLowTtl_RoundtripTimeIsNonZero to fix macOS flakiness#125774rzikm merged 2 commits intodotnet:mainfrom
Conversation
…S 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>
|
/azp run runtime-libraries coreclr-outerloop |
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
|
No pipelines are associated with this pull request. |
|
/azp runtime-coreclr libraries-outerloop |
|
Command 'runtime-coreclr' is not supported by Azure Pipelines. Supported commands
See additional documentation. |
|
/azp run runtime-coreclr libraries-outerloop |
|
No pipelines are associated with this pull request. |
|
/azp list |
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Adjusts a flaky System.Net.Ping OuterLoop test on macOS by increasing the TTL used for a TtlExpired/TimeExceeded scenario so the measured round-trip time is more likely to be non-zero.
Changes:
- Increase TTL in
SendPingWithLowTtl_RoundtripTimeIsNonZerofrom1to5. - Add explanatory comments describing the macOS raw-socket RTT truncation behavior and why a higher TTL helps.
Comments suppressed due to low confidence (1)
src/libraries/System.Net.Ping/tests/FunctionalTests/PingTest.cs:832
- Setting options.Ttl = 5 can cause the ping to reach the configured external host when it is within <=5 hops, which would produce IPStatus.Success and fail the assertion that requires TimeExceeded/TtlExpired. To keep this test robust across network topologies, consider dynamically selecting a TTL that results in a non-Success status (e.g., probe with increasing TTL to find hop count and then use a smaller TTL), or skip the test when the host is too close for the chosen TTL.
// 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++)
{
PingReply pingReply = await ping.SendPingAsync(host, TestSettings.PingTimeout, payload, options);
You can also share your feedback on Copilot code review. Take the survey.
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Related ping test didn't fail in the outerloop run |
|
/ba-g Test failures are unrelated |
SendPingWithLowTtl_RoundtripTimeIsNonZerohas been consistently failing on macOS since it was introduced (Mar 11, 29 failures across 17 builds on bothosx.15.amd64andosx.26.arm64).Root Cause
The test sends a ping with
TTL=1and asserts that theTtlExpiredreply hasRoundtripTime > 0. On macOS, the raw socket Ping implementation computes RTT via:The
(long)cast truncates sub-millisecond values to 0. On CI machines, the first-hop router responds toTTL=1pings in under 1ms, so all 3 retry attempts reportRoundtripTime == 0.This doesn't affect Windows, which uses
IcmpSendEchowith OS-reported RTT values.Fix
Increase TTL from 1 to 5 so the ICMP packet travels further before expiring, increasing the likelihood of a measurable (>0ms) round-trip time.
Example failure log: https://helixr1107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-heads-main-3b34e246c46a48c489/System.Net.Ping.Functional.Tests/3/console.52343950.log?helixlogtype=result