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

Robustify a name resolution test #63259

Merged
merged 2 commits into from
Jan 4, 2022
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 @@ -155,7 +155,18 @@ public void TryGetAddrInfo_LocalHost_TryGetNameInfo()
Assert.NotNull(aliases);
Assert.NotNull(addresses);

string name = NameResolutionPal.TryGetNameInfo(addresses[0], out error, out nativeErrorCode);
// Not all addresses returned by TryGetAddInfo can be resolved to host names, depending on network configuration.
// However at least one should be.
string name = null;
foreach(IPAddress address in addresses)
{
name = NameResolutionPal.TryGetNameInfo(address, out error, out nativeErrorCode);
if (error != SocketError.HostNotFound)
{
break;
}
}

Assert.Equal(SocketError.Success, error);
Assert.NotNull(name);
}
Expand All @@ -181,12 +192,22 @@ public void TryGetAddrInfo_HostName_TryGetNameInfo()
Assert.NotNull(aliases);
Assert.NotNull(addresses);

string name = NameResolutionPal.TryGetNameInfo(addresses[0], out error, out nativeErrorCode);
if (error == SocketError.HostNotFound)
// Not all addresses returned by TryGetAddInfo can be resolved to host names, depending on network configuration.
// However at least one should be.
string name = null;
foreach(IPAddress address in addresses)
{
name = NameResolutionPal.TryGetNameInfo(address, out error, out nativeErrorCode);
if (error != SocketError.HostNotFound)
{
break;
}
}

if (error == SocketError.HostNotFound && Environment.OSVersion.Platform == PlatformID.Unix)
{
// On Unix, getaddrinfo returns private ipv4 address for hostname. If the OS doesn't have the
// reverse dns lookup entry for this address, getnameinfo returns host not found.
Assert.Equal(PlatformID.Unix, Environment.OSVersion.Platform);
return;
}

Expand Down