Skip to content

Commit

Permalink
Added tests for SlidingWindow statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
KamilSlusarczykDotDigital committed Apr 14, 2023
1 parent 5ef7f16 commit 8cbffc2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public async Task ThrowsWhenAcquiringMoreThanLimit()
[Fact]
public async Task CanAcquireAsyncResource()
{
await Fixture.ClearStatisticsAsync("Test_CanAcquireAsyncResource_SW");

using var limiter = new RedisSlidingWindowRateLimiter<string>(
"Test_CanAcquireAsyncResource_SW",
new RedisSlidingWindowRateLimiterOptions
Expand All @@ -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);
}
}
}

0 comments on commit 8cbffc2

Please sign in to comment.