Skip to content

Commit

Permalink
Add Dispose implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Feb 16, 2024
1 parent 4b9c202 commit 45b898d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/SLCore.UnitTests/State/ActiveConfigScopeTrackerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IThreadHandling>());

testSubject.Dispose();
asyncLock.Verify(x => x.Dispose());
}

private static void VerifyThreadHandling(Mock<IThreadHandling> threadHandling)
{
Expand Down
9 changes: 7 additions & 2 deletions src/SLCore/State/ActiveConfigScopeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -131,4 +131,9 @@ await configurationScopeService.DidRemoveConfigurationScopeAsync(
currentConfigScope = null;
}
}

public void Dispose()
{
asyncLock?.Dispose();
}
}

0 comments on commit 45b898d

Please sign in to comment.