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

NameResolution-Tests: enable GetHostEntryAsync_InvalidHost_LogsError on Windows #47034

Merged
merged 2 commits into from
Jan 21, 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 @@ -63,7 +63,6 @@ public void GetHostEntry_InvalidHost_LogsError()
}

[ConditionalFact]
[PlatformSpecific(~TestPlatforms.Windows)] // Unreliable on Windows.
public async Task GetHostEntryAsync_InvalidHost_LogsError()
{
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error))
Expand All @@ -79,8 +78,7 @@ await listener.RunWithCallbackAsync(ev => events.Enqueue(ev), async () =>
}
catch (SocketException e) when (e.SocketErrorCode == SocketError.HostNotFound)
{
// Wait a bit to let the event source write it's log
await Task.Delay(100).ConfigureAwait(false);
await WaitForErrorEventAsync(events);
}
catch (Exception e)
{
Expand All @@ -97,6 +95,20 @@ await listener.RunWithCallbackAsync(ev => events.Enqueue(ev), async () =>
Assert.NotNull(ev.Payload[2]);
}
}

static async Task WaitForErrorEventAsync(ConcurrentQueue<EventWrittenEventArgs> events)
{
const int ErrorEventId = 5;
DateTime startTime = DateTime.UtcNow;

while (!events.Any(e => e.EventId == ErrorEventId))
{
if (DateTime.UtcNow.Subtract(startTime) > TimeSpan.FromSeconds(30))
throw new TimeoutException("Timeout waiting for error event");

await Task.Delay(100);
}
}
}

[ConditionalFact]
Expand Down