diff --git a/src/SLCore.UnitTests/State/ActiveConfigScopeTrackerTests.cs b/src/SLCore.UnitTests/State/ActiveConfigScopeTrackerTests.cs index 69a459645a..7ac36cdca6 100644 --- a/src/SLCore.UnitTests/State/ActiveConfigScopeTrackerTests.cs +++ b/src/SLCore.UnitTests/State/ActiveConfigScopeTrackerTests.cs @@ -161,6 +161,18 @@ public void GetCurrent_ReturnsBoundScope() VerifyThreadHandling(threadHandling); VerifyLockTakenSynchronouslyAndReleased(asyncLock, lockRelease); } + + [TestMethod] + public void Dispose_DisposesLock() + { + ConfigureServiceProvider(out var serviceProvider, out _); + ConfigureAsyncLockFactory(out var lockFactory, out var asyncLock, out _); + + var testSubject = CreateTestSubject(serviceProvider.Object, lockFactory.Object, Mock.Of()); + + testSubject.Dispose(); + asyncLock.Verify(x => x.Dispose()); + } private static void VerifyThreadHandling(Mock threadHandling) { diff --git a/src/SLCore/State/ActiveConfigScopeTracker.cs b/src/SLCore/State/ActiveConfigScopeTracker.cs index 712af461b9..ce34762991 100644 --- a/src/SLCore/State/ActiveConfigScopeTracker.cs +++ b/src/SLCore/State/ActiveConfigScopeTracker.cs @@ -31,7 +31,7 @@ namespace SonarLint.VisualStudio.SLCore.State; -internal interface IActiveConfigScopeTracker +internal interface IActiveConfigScopeTracker : IDisposable { ConfigurationScope Current { get; } Task SetCurrentConfigScopeAsync(string id, string connectionId = null, string sonarProjectKey = null); @@ -54,7 +54,7 @@ public ConfigurationScope(string id, string connectionId = null, string sonarPro [Export(typeof(IActiveConfigScopeTracker))] [PartCreationPolicy(CreationPolicy.Shared)] -internal class ActiveConfigScopeTracker : IActiveConfigScopeTracker +internal sealed class ActiveConfigScopeTracker : IActiveConfigScopeTracker { private readonly IAsyncLock asyncLock; @@ -131,4 +131,9 @@ await configurationScopeService.DidRemoveConfigurationScopeAsync( currentConfigScope = null; } } + + public void Dispose() + { + asyncLock?.Dispose(); + } }