Skip to content

Commit

Permalink
Assert ETW session is deleted on dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam committed Jan 13, 2021
1 parent 27b5f6e commit 138f5c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class GcMetricsProvider : IMetricsProvider, IDisposable
internal const string GcGen2SizeName = "clr.gc.gen2size";
internal const string GcGen3SizeName = "clr.gc.gen3size";

private const string SessionNamePrefix = "EtwSessionForCLRElasticApm_";
internal const string SessionNamePrefix = "EtwSessionForCLRElasticApm_";

private readonly bool _collectGcCount;
private readonly bool _collectGcGen0Size;
Expand Down
10 changes: 7 additions & 3 deletions test/Elastic.Apm.Tests/MetricsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
using Elastic.Apm.Metrics.MetricsProvider;
using Elastic.Apm.Tests.Utilities;
using FluentAssertions;
using Microsoft.Diagnostics.Tracing.Session;
using Moq;
using Xunit;
using Xunit.Abstractions;
#if !NETCOREAPP2_1
using Elastic.Apm.Helpers;

#endif

namespace Elastic.Apm.Tests
{
public class MetricsTests : LoggingTestBase
Expand Down Expand Up @@ -337,6 +335,12 @@ public void CollectGcMetrics()
gcMetricsProvider.IsMetricAlreadyCaptured.Should().BeTrue();
#endif
}

if (PlatformDetection.IsDotNetFullFramework)
{
var activeSessions = TraceEventSession.GetActiveSessionNames();
activeSessions.Should().NotContain(s => s.StartsWith(GcMetricsProvider.SessionNamePrefix));
}
}

internal class MetricsProviderWithException : IMetricsProvider
Expand Down

0 comments on commit 138f5c8

Please sign in to comment.