From 8cbffc2485ab042c9e496e72b72ba99baaed7fef Mon Sep 17 00:00:00 2001 From: Kamil Slusarczyk Date: Fri, 14 Apr 2023 11:28:53 +0200 Subject: [PATCH] Added tests for SlidingWindow statistics --- .../UnitTests/SlidingWindowUnitTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs b/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs index 3d9f762..b9858e8 100644 --- a/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs +++ b/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs @@ -78,6 +78,8 @@ public async Task ThrowsWhenAcquiringMoreThanLimit() [Fact] public async Task CanAcquireAsyncResource() { + await Fixture.ClearStatisticsAsync("Test_CanAcquireAsyncResource_SW"); + using var limiter = new RedisSlidingWindowRateLimiter( "Test_CanAcquireAsyncResource_SW", new RedisSlidingWindowRateLimiterOptions @@ -92,6 +94,17 @@ public async Task CanAcquireAsyncResource() using var lease2 = await limiter.AcquireAsync(); Assert.False(lease2.IsAcquired); + + var stats = limiter.GetStatistics()!; + Assert.Equal(1, stats.TotalSuccessfulLeases); + Assert.Equal(1, stats.TotalFailedLeases); + Assert.Equal(0, stats.CurrentAvailablePermits); + + lease.Dispose(); + lease2.Dispose(); + + stats = limiter.GetStatistics()!; + Assert.Equal(0, stats.CurrentAvailablePermits); } } }