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

Add multi-subscriber listener test #25469

Merged
merged 1 commit into from
Nov 23, 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
22 changes: 22 additions & 0 deletions sdk/core/Azure.Core/tests/AzureEventSourceListenerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics.Tracing;
using System.Linq;
using Azure.Core.Diagnostics;
using Moq;
using NUnit.Framework;

namespace Azure.Core.Tests
Expand All @@ -32,6 +33,27 @@ public void CallsCallbackWhenMessageIsLogged()
Assert.NotNull(singleInvocation.Item2);
}

[Test]
public void FiltersMessagesUsingLevel()
{
var warningInvocations = new List<(EventWrittenEventArgs, string)>();
var verboseInvocations = new List<(EventWrittenEventArgs, string)>();
using var verboseListener = new AzureEventSourceListener((args, s) => verboseInvocations.Add((args, s)), EventLevel.Verbose);
using var warningListener = new AzureEventSourceListener((args, s) => warningInvocations.Add((args, s)), EventLevel.Warning);

AzureCoreEventSource.Singleton.ErrorResponse("id", 500, "GET", "http", 5);
AzureCoreEventSource.Singleton.Request("id", "GET", "http", "header", "Test-SDK");

Assert.AreEqual(1, warningInvocations.Count);
var warningInvocation = warningInvocations.Single();
Assert.AreEqual("ErrorResponse", warningInvocation.Item1.EventName);
Assert.NotNull(warningInvocation.Item2);

Assert.AreEqual(2, verboseInvocations.Count);
Assert.True(verboseInvocations.Any(c=>c.Item1.EventName == "ErrorResponse"));
Assert.True(verboseInvocations.Any(c=>c.Item1.EventName == "Request"));
}

[Test]
public void IgnoresEventCountersEvents()
{
Expand Down