Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Net.Ping: Skip TimeoutIsRespected test if network is unreachable #58745

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;

using Xunit;
using Microsoft.DotNet.XUnitExtensions;

namespace System.Net.NetworkInformation.Tests
{
Expand All @@ -19,7 +20,7 @@ public class UnixPingUtilityTests
{
private const int IcmpHeaderLengthInBytes = 8;

[Theory]
[ConditionalTheory]
[InlineData(0)]
[InlineData(100)]
[InlineData(1000)]
Expand All @@ -32,11 +33,24 @@ public static void TimeoutIsRespected(int timeout)
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;

bool destinationNetUnreachable = false;
p.OutputDataReceived += delegate (object sendingProcess, DataReceivedEventArgs outputLine)
{
if (outputLine.Data?.Contains("Destination Net Unreachable", StringComparison.OrdinalIgnoreCase) == true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this text get localized on any OSes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows it is, but this file is specific to Unix where I haven't seen this output being localized.

We also already rely on the English strings in ParseReturnedPacketSize and ParseNumPingsSent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (outputLine.Data?.Contains("Destination Net Unreachable", StringComparison.OrdinalIgnoreCase) == true)
if (outputLine.Data?.Contains("Destination Net Unreachable", StringComparison.OrdinalIgnoreCase))

maybe we should have an analyzer for == true and != false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danmoseley this doesn't work because of the null conditional operator so we need the explicit comparison.

destinationNetUnreachable = true;
};

Stopwatch stopWatch = Stopwatch.StartNew();

p.Start();
p.BeginOutputReadLine();
p.WaitForExit();

if (destinationNetUnreachable)
{
throw new SkipTestException($"Network doesn't route {TestSettings.UnreachableAddress}, skipping test.");
}

//ensure that the process takes longer than or within 10ms of 'timeout', with a 5s maximum
Assert.InRange(stopWatch.ElapsedMilliseconds, timeout - 10, 5000);
}
Expand Down