Skip to content

[release/8.0-staging] Move DNS EventSource tests to RemoteExecutor #116609

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

Merged
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 @@ -6,6 +6,7 @@
using System.Linq;
using System.Net.Sockets;
using System.Threading.Tasks;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

Expand All @@ -28,72 +29,92 @@ public static void EventSource_ExistsWithCorrectId()
Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest"));
}

[ConditionalFact]
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void GetHostEntry_InvalidHost_LogsError()
{
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error))
try
{
var events = new ConcurrentQueue<EventWrittenEventArgs>();

listener.RunWithCallback(ev => events.Enqueue(ev), () =>
RemoteExecutor.Invoke(static () =>
{
try
{
Dns.GetHostEntry(Configuration.Sockets.InvalidHost);
throw new SkipTestException("GetHostEntry should fail but it did not.");
}
catch (SocketException e) when (e.SocketErrorCode == SocketError.HostNotFound)
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error))
{
var events = new ConcurrentQueue<EventWrittenEventArgs>();

listener.RunWithCallback(ev => events.Enqueue(ev), () =>
{
try
{
Dns.GetHostEntry(Configuration.Sockets.InvalidHost);
throw new SkipTestException("GetHostEntry should fail but it did not.");
}
catch (SocketException e) when (e.SocketErrorCode == SocketError.HostNotFound)
{
}
catch (Exception e)
{
throw new SkipTestException($"GetHostEntry failed unexpectedly: {e.Message}");
}
});

Assert.True(events.Count > 0, "events.Count should be > 0");
foreach (EventWrittenEventArgs ev in events)
{
Assert.True(ev.Payload.Count >= 3);
Assert.NotNull(ev.Payload[0]);
Assert.NotNull(ev.Payload[1]);
Assert.NotNull(ev.Payload[2]);
}
}
catch (Exception e)
{
throw new SkipTestException($"GetHostEntry failed unexpectedly: {e.Message}");
}
});

Assert.True(events.Count > 0, "events.Count should be > 0");
foreach (EventWrittenEventArgs ev in events)
{
Assert.True(ev.Payload.Count >= 3);
Assert.NotNull(ev.Payload[0]);
Assert.NotNull(ev.Payload[1]);
Assert.NotNull(ev.Payload[2]);
}
}).Dispose();
}
catch (Exception ex) when (ex.ToString().Contains(nameof(SkipTestException), StringComparison.Ordinal))
{
throw new SkipTestException(ex.ToString());
}
}

[ConditionalFact]
public async Task GetHostEntryAsync_InvalidHost_LogsError()
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void GetHostEntryAsync_InvalidHost_LogsError()
{
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error))
try
{
var events = new ConcurrentQueue<EventWrittenEventArgs>();

await listener.RunWithCallbackAsync(ev => events.Enqueue(ev), async () =>
RemoteExecutor.Invoke(static async () =>
{
try
{
await Dns.GetHostEntryAsync(Configuration.Sockets.InvalidHost).ConfigureAwait(false);
throw new SkipTestException("GetHostEntryAsync should fail but it did not.");
}
catch (SocketException e) when (e.SocketErrorCode == SocketError.HostNotFound)
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Error))
{
await WaitForErrorEventAsync(events);
var events = new ConcurrentQueue<EventWrittenEventArgs>();

await listener.RunWithCallbackAsync(ev => events.Enqueue(ev), async () =>
{
try
{
await Dns.GetHostEntryAsync(Configuration.Sockets.InvalidHost).ConfigureAwait(false);
throw new SkipTestException("GetHostEntryAsync should fail but it did not.");
}
catch (SocketException e) when (e.SocketErrorCode == SocketError.HostNotFound)
{
await WaitForErrorEventAsync(events);
}
catch (Exception e)
{
throw new SkipTestException($"GetHostEntryAsync failed unexpectedly: {e.Message}");
}
}).ConfigureAwait(false);

Assert.True(events.Count > 0, "events.Count should be > 0");
foreach (EventWrittenEventArgs ev in events)
{
Assert.True(ev.Payload.Count >= 3);
Assert.NotNull(ev.Payload[0]);
Assert.NotNull(ev.Payload[1]);
Assert.NotNull(ev.Payload[2]);
}
}
catch (Exception e)
{
throw new SkipTestException($"GetHostEntryAsync failed unexpectedly: {e.Message}");
}
}).ConfigureAwait(false);

Assert.True(events.Count > 0, "events.Count should be > 0");
foreach (EventWrittenEventArgs ev in events)
{
Assert.True(ev.Payload.Count >= 3);
Assert.NotNull(ev.Payload[0]);
Assert.NotNull(ev.Payload[1]);
Assert.NotNull(ev.Payload[2]);
}
}).Dispose();
}
catch (Exception ex) when (ex.ToString().Contains(nameof(SkipTestException), StringComparison.Ordinal))
{
throw new SkipTestException(ex.ToString());
}

static async Task WaitForErrorEventAsync(ConcurrentQueue<EventWrittenEventArgs> events)
Expand All @@ -110,32 +131,42 @@ static async Task WaitForErrorEventAsync(ConcurrentQueue<EventWrittenEventArgs>
}
}

[ConditionalFact]
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void GetHostEntry_ValidName_NoErrors()
{
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Verbose))
try
{
var events = new ConcurrentQueue<EventWrittenEventArgs>();

listener.RunWithCallback(ev => events.Enqueue(ev), () =>
RemoteExecutor.Invoke(static () =>
{
try
{
Dns.GetHostEntryAsync("localhost").GetAwaiter().GetResult();
Dns.GetHostEntryAsync(IPAddress.Loopback).GetAwaiter().GetResult();
Dns.GetHostEntry("localhost");
Dns.GetHostEntry(IPAddress.Loopback);
}
catch (Exception e)
using (var listener = new TestEventListener("Private.InternalDiagnostics.System.Net.NameResolution", EventLevel.Verbose))
{
throw new SkipTestException($"Localhost lookup failed unexpectedly: {e.Message}");
var events = new ConcurrentQueue<EventWrittenEventArgs>();

listener.RunWithCallback(ev => events.Enqueue(ev), () =>
{
try
{
Dns.GetHostEntryAsync("localhost").GetAwaiter().GetResult();
Dns.GetHostEntryAsync(IPAddress.Loopback).GetAwaiter().GetResult();
Dns.GetHostEntry("localhost");
Dns.GetHostEntry(IPAddress.Loopback);
}
catch (Exception e)
{
throw new SkipTestException($"Localhost lookup failed unexpectedly: {e.Message}");
}
});

// We get some traces.
Assert.True(events.Count() > 0);
// No errors or warning for successful query.
Assert.True(events.Count(ev => (int)ev.Level > (int)EventLevel.Informational) == 0);
}
});

// We get some traces.
Assert.True(events.Count() > 0);
// No errors or warning for successful query.
Assert.True(events.Count(ev => (int)ev.Level > (int)EventLevel.Informational) == 0);
}).Dispose();
}
catch (Exception ex) when (ex.ToString().Contains(nameof(SkipTestException), StringComparison.Ordinal))
{
throw new SkipTestException(ex.ToString());
}
}
}
Expand Down
Loading