Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Re-enable hostname resolution test on Linux, but skip under certain conditions#28324

Merged
rmkerr merged 6 commits intodotnet:masterfrom
rmkerr:NameResolution_UnixHostname_DoesNotResolve
Mar 22, 2018
Merged

Re-enable hostname resolution test on Linux, but skip under certain conditions#28324
rmkerr merged 6 commits intodotnet:masterfrom
rmkerr:NameResolution_UnixHostname_DoesNotResolve

Conversation

@rmkerr
Copy link
Contributor

@rmkerr rmkerr commented Mar 21, 2018

This test assumed that the host name can always be resolved, which isn't guaranteed on Unix.

In the interest of "testing as much as we can" I'm going to enable the test, but pass it if we get the specific error that indicates we haven't been able to resolve the localhost on Unix. That way we'll hopefully still see failures if things go wrong somewhere else.

The logic to skip the test is taken from another test in the same file:

[Fact]
public void TryGetAddrInfo_HostName_TryGetNameInfo()
{
string hostName = NameResolutionPal.GetHostName();
Assert.NotNull(hostName);
IPHostEntry hostEntry;
int nativeErrorCode;
SocketError error = NameResolutionPal.TryGetAddrInfo(hostName, out hostEntry, out nativeErrorCode);
if (error == SocketError.HostNotFound)
{
// On Unix, getaddrinfo returns host not found, if all the machine discovery settings on the local network
// is turned off. Hence dns lookup for it's own hostname fails.
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
return;
}

Fixes: #20245

@rmkerr rmkerr added test bug Problem in test source code (most likely) area-System.Net labels Mar 21, 2018
@rmkerr rmkerr self-assigned this Mar 21, 2018
@rmkerr rmkerr requested review from a team and danmoseley March 21, 2018 18:14
Copy link
Contributor

@caesar-chen caesar-chen left a comment

Choose a reason for hiding this comment

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

LGTM.

{
// On Unix, we are not guaranteed to be able to resove the local host. The ability to do so depends on the
// machine configurations, which varies by distro and is often inconsistent.
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Copy link
Member

Choose a reason for hiding this comment

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

Not: I wonder if it would be "better" to move OS check into the if-condition. If we ever get HostNotFound on Windows, it should ideally fail on the Assert.Equal(SocketError.Succes, error); line.
If this is established pattern in other tests, I'm fine leaving it as is.

Copy link
Contributor

@davidsh davidsh Mar 21, 2018

Choose a reason for hiding this comment

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

I would rather see the OS checks in the if-condition. This is usually how we do OS platform-specific tests using 'ifs'. It makes the code easier to read if we see things like this:

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
    // Test setup and assertions specific to Linux
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
    // Test setup and assertions specific to OSX
}

// ...

Copy link
Member

Choose a reason for hiding this comment

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

This is really not specific to OS but given environment. Linux can resolve the names if configured as such. Add it will in most cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it's better to do things this way, or to set up a capability as mentioned by @wfurt below?

Copy link
Contributor

Choose a reason for hiding this comment

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

Capabilities are not used for this kind of thing. This is basically a platform difference in behavior that you want to capture in a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change. I agree that it's an improvement over the check I initially added -- it should make failures a lot more clear.

@wfurt
Copy link
Member

wfurt commented Mar 21, 2018

Can we turn this into test Capability?
I think there were more tests making similar assumptions.
That would also allow us to skip and track that instead of instant pass.

@karelz
Copy link
Member

karelz commented Mar 21, 2018

Can we turn this into test Capability?

Long-term, why not if it is possible. Short-term, let's just disable the test on Linux / skip the testing as @rmkerr proposes.

@rmkerr
Copy link
Contributor Author

rmkerr commented Mar 22, 2018

I can't see why the Linux build failed, so I'm rerunning it. The Windows failures are unrelated, but I'm rerunning them anyways since I have the chance.

@dotnet-bot test Linux x64 Release Build
@dotnet-bot test Windows x64 Debug Build
@dotnet-bot test Windows x86 Release Build
@dotnet-bot test Windows x64 Release Build

@rmkerr rmkerr merged commit 69ba7ef into dotnet:master Mar 22, 2018
@karelz karelz added this to the 2.1.0 milestone Mar 27, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…onditions (dotnet/corefx#28324)

This test assumed that the host name can always be resolved, which isn't guaranteed on Unix.

In the interest of "testing as much as we can" this change enables the test, but passes it if we get the specific error that indicates we haven't been able to resolve the localhost on Unix. That way we'll hopefully still see failures if things go wrong somewhere else.

Fixes: dotnet/corefx#20245

Commit migrated from dotnet/corefx@69ba7ef
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net test bug Problem in test source code (most likely)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test failures: System.Net.NameResolution.PalTests.NameResolutionPalTests / GetHostByName_HostName & TryGetAddrInfo_HostName

5 participants