Skip to content

Commit ff26663

Browse files
committed
Fix analyzer issues.
1 parent 6740969 commit ff26663

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

test/Autofac.Pooling.Test/Common/PooledComponent.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Autofac.Pooling.Tests.Common;
66

7+
[SuppressMessage("CA1063", "CA1063", Justification = "Dispose remains simple here for testing.")]
78
public class PooledComponent : IPooledService, IPooledComponent, IDisposable
89
{
910
public int GetCalled
@@ -31,6 +32,7 @@ public void OnReturnToPool()
3132
ReturnCalled++;
3233
}
3334

35+
[SuppressMessage("CA1063", "CA1063", Justification = "Dispose remains simple here for testing.")]
3436
public void Dispose()
3537
{
3638
DisposeCalled++;

test/Autofac.Pooling.Test/ConcurrencyTests.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task CanUsePoolConcurrentlyWithCustomPolicyToBlockOnMaxUsage()
4141
{
4242
var builder = new ContainerBuilder();
4343

44-
var blockingPolicy = new BlockingPolicy<PooledComponent>(4);
44+
using var blockingPolicy = new BlockingPolicy<PooledComponent>(4);
4545

4646
builder.RegisterType<PooledComponent>().As<IPooledService>()
4747
.PooledInstancePerLifetimeScope(blockingPolicy);
@@ -60,10 +60,11 @@ await Task.WhenAll(Enumerable.Range(0, 10000).Select(i => Task.Run(() =>
6060
container.Dispose();
6161
}
6262

63-
private class BlockingPolicy<TLimit> : DefaultPooledRegistrationPolicy<TLimit>
63+
private class BlockingPolicy<TLimit> : DefaultPooledRegistrationPolicy<TLimit>, IDisposable
6464
where TLimit : class
6565
{
6666
private readonly SemaphoreSlim _semaphore;
67+
private bool _disposedValue;
6768

6869
public BlockingPolicy(int maxConcurrentInstances) : base(maxConcurrentInstances)
6970
{
@@ -87,5 +88,25 @@ public override bool Return(TLimit pooledObject)
8788

8889
return base.Return(pooledObject);
8990
}
91+
92+
protected virtual void Dispose(bool disposing)
93+
{
94+
if (!_disposedValue)
95+
{
96+
if (disposing)
97+
{
98+
_semaphore.Dispose();
99+
}
100+
101+
_disposedValue = true;
102+
}
103+
}
104+
105+
public void Dispose()
106+
{
107+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
108+
Dispose(disposing: true);
109+
GC.SuppressFinalize(this);
110+
}
90111
}
91112
}

test/Autofac.Pooling.Test/PoolingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Autofac.Pooling.Tests.Common;
22
using Xunit;
33

4-
namespace Autofac.Pooling.Tests;
4+
namespace Autofac.Pooling.Test;
55

66
public class PoolingTest
77
{

0 commit comments

Comments
 (0)