IDisposable fix

This commit is contained in:
Dylan Dmitri Gray 2019-05-16 16:59:40 -07:00
parent ac305849e3
commit 04ce6ef4c8
2 changed files with 11 additions and 6 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Microsoft.AspNetCore.RequestThrottling namespace Microsoft.AspNetCore.RequestThrottling
{ {
internal class SemaphoreWrapper internal class SemaphoreWrapper : IDisposable
{ {
private SemaphoreSlim _semaphore; private SemaphoreSlim _semaphore;
@ -29,5 +29,10 @@ namespace Microsoft.AspNetCore.RequestThrottling
{ {
get => _semaphore.CurrentCount; get => _semaphore.CurrentCount;
} }
public void Dispose()
{
_semaphore.Dispose();
}
} }
} }

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests
[Fact] [Fact]
public async Task TracksQueueLength() public async Task TracksQueueLength()
{ {
var s = new SemaphoreWrapper(1); using var s = new SemaphoreWrapper(1);
Assert.Equal(1, s.Count); Assert.Equal(1, s.Count);
await s.EnterQueue(); await s.EnterQueue();
@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests
[Fact] [Fact]
public void DoesNotWaitIfSpaceAvailible() public void DoesNotWaitIfSpaceAvailible()
{ {
var s = new SemaphoreWrapper(2); using var s = new SemaphoreWrapper(2);
var t1 = s.EnterQueue(); var t1 = s.EnterQueue();
Assert.True(t1.IsCompleted); Assert.True(t1.IsCompleted);
@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests
[Fact] [Fact]
public async Task WaitsIfNoSpaceAvailible() public async Task WaitsIfNoSpaceAvailible()
{ {
var s = new SemaphoreWrapper(1); using var s = new SemaphoreWrapper(1);
await s.EnterQueue(); await s.EnterQueue();
var waitingTask = s.EnterQueue(); var waitingTask = s.EnterQueue();
@ -56,8 +56,8 @@ namespace Microsoft.AspNetCore.RequestThrottling.Tests
[Fact] [Fact]
public async Task IsEncapsulated() public async Task IsEncapsulated()
{ {
var s1 = new SemaphoreWrapper(1); using var s1 = new SemaphoreWrapper(1);
var s2 = new SemaphoreWrapper(1); using var s2 = new SemaphoreWrapper(1);
await s1.EnterQueue(); await s1.EnterQueue();
await s2.EnterQueue().TimeoutAfter(TimeSpan.FromSeconds(30)); await s2.EnterQueue().TimeoutAfter(TimeSpan.FromSeconds(30));