Skip to content

Commit 1f493b3

Browse files
authored
NameResolution-Tests: enable GetHostEntryAsync_InvalidHost_LogsError on Windows (#47034)
* Enable GetHostEntryAsync_InvalidHost_LogsError on Windows too * Use WaitForErrorEventAsync instead of a naive Task.Delay Cf. #47034 (comment)
1 parent 661885a commit 1f493b3

File tree

1 file changed

+15
-3
lines changed
  • src/libraries/System.Net.NameResolution/tests/FunctionalTests

1 file changed

+15
-3
lines changed

src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public void GetHostEntry_InvalidHost_LogsError()
6363
}
6464

6565
[ConditionalFact]
66-
[PlatformSpecific(~TestPlatforms.Windows)] // Unreliable on Windows.
6766
public async Task GetHostEntryAsync_InvalidHost_LogsError()
6867
{
6968
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error))
@@ -79,8 +78,7 @@ await listener.RunWithCallbackAsync(ev => events.Enqueue(ev), async () =>
7978
}
8079
catch (SocketException e) when (e.SocketErrorCode == SocketError.HostNotFound)
8180
{
82-
// Wait a bit to let the event source write it's log
83-
await Task.Delay(100).ConfigureAwait(false);
81+
await WaitForErrorEventAsync(events);
8482
}
8583
catch (Exception e)
8684
{
@@ -97,6 +95,20 @@ await listener.RunWithCallbackAsync(ev => events.Enqueue(ev), async () =>
9795
Assert.NotNull(ev.Payload[2]);
9896
}
9997
}
98+
99+
static async Task WaitForErrorEventAsync(ConcurrentQueue<EventWrittenEventArgs> events)
100+
{
101+
const int ErrorEventId = 5;
102+
DateTime startTime = DateTime.UtcNow;
103+
104+
while (!events.Any(e => e.EventId == ErrorEventId))
105+
{
106+
if (DateTime.UtcNow.Subtract(startTime) > TimeSpan.FromSeconds(30))
107+
throw new TimeoutException("Timeout waiting for error event");
108+
109+
await Task.Delay(100);
110+
}
111+
}
100112
}
101113

102114
[ConditionalFact]

0 commit comments

Comments
 (0)