Skip to content

Commit

Permalink
Add multi-subscriber listener test (#25469)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym authored Nov 23, 2021
1 parent 6c2c75b commit 27891d4
Showing 1 changed file with 22 additions and 0 deletions.
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

0 comments on commit 27891d4

Please sign in to comment.