diff --git a/test/RedisRateLimiting.Tests/UnitTests/ConcurrencyUnitTests.cs b/test/RedisRateLimiting.Tests/UnitTests/ConcurrencyUnitTests.cs index 71e246d..3c63a96 100644 --- a/test/RedisRateLimiting.Tests/UnitTests/ConcurrencyUnitTests.cs +++ b/test/RedisRateLimiting.Tests/UnitTests/ConcurrencyUnitTests.cs @@ -41,7 +41,7 @@ public void InvalidOptionsThrows() public async Task ThrowsWhenAcquiringMoreThanLimit() { var limiter = new RedisConcurrencyRateLimiter( - string.Empty, + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, @@ -55,10 +55,8 @@ public async Task ThrowsWhenAcquiringMoreThanLimit() [Fact] public async Task CanAcquireAsyncResource() { - await Fixture.ClearStatisticsAsync("cc", "Test_CanAcquireAsyncResource"); - using var limiter = new RedisConcurrencyRateLimiter( - "Test_CanAcquireAsyncResource", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, @@ -91,7 +89,7 @@ public async Task CanAcquireAsyncResource() public void CanAcquireResource() { using var limiter = new RedisConcurrencyRateLimiter( - "Test_CanAcquireResource", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, @@ -117,7 +115,7 @@ public void CanAcquireResource() public async Task CanAcquireResourceAsyncQueuesAndGrabsOldest() { using var limiter = new RedisConcurrencyRateLimiter( - "Test_CanAcquireResourceAsyncQueuesAndGrabsOldest", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, @@ -151,7 +149,7 @@ public async Task CanAcquireResourceAsyncQueuesAndGrabsOldest() public async Task FailsWhenQueuingMoreThanLimit() { using var limiter = new RedisConcurrencyRateLimiter( - "Test_FailsWhenQueuingMoreThanLimit", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, @@ -169,10 +167,8 @@ public async Task FailsWhenQueuingMoreThanLimit() [Fact] public async Task QueueAvailableAfterQueueLimitHitAndResourcesBecomeAvailable() { - await Fixture.ClearStatisticsAsync("cc", "Test_QueueAvailableAfterQueueLimitHitAndResourcesBecomeAvailable"); - using var limiter = new RedisConcurrencyRateLimiter( - "Test_QueueAvailableAfterQueueLimitHitAndResourcesBecomeAvailable", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, @@ -217,7 +213,7 @@ public async Task QueueAvailableAfterQueueLimitHitAndResourcesBecomeAvailable() public async Task CanDequeueMultipleResourcesAtOnce() { using var limiter = new RedisConcurrencyRateLimiter( - "Test_CanDequeueMultipleResourcesAtOnce", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 2, @@ -249,7 +245,7 @@ public async Task CanDequeueMultipleResourcesAtOnce() public async Task CanCancelAcquireAsyncAfterQueuing() { var limiter = new RedisConcurrencyRateLimiter( - "CanCancelAcquireAsyncAfterQueuing", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, @@ -299,7 +295,7 @@ public async Task CanCancelAcquireAsyncAfterQueuing() public async Task GetPermitWhilePermitEmptyQueueNotEmptyGetsQueued() { using var limiter = new RedisConcurrencyRateLimiter( - "GetPermitWhilePermitEmptyQueueNotEmptyGetsQueued", + partitionKey: Guid.NewGuid().ToString(), new RedisConcurrencyRateLimiterOptions { PermitLimit = 1, diff --git a/test/RedisRateLimiting.Tests/UnitTests/FixedWindowUnitTests.cs b/test/RedisRateLimiting.Tests/UnitTests/FixedWindowUnitTests.cs index 0023868..12edf89 100644 --- a/test/RedisRateLimiting.Tests/UnitTests/FixedWindowUnitTests.cs +++ b/test/RedisRateLimiting.Tests/UnitTests/FixedWindowUnitTests.cs @@ -50,7 +50,7 @@ public void InvalidOptionsThrows() public async Task ThrowsWhenAcquiringMoreThanLimit() { var limiter = new RedisFixedWindowRateLimiter( - string.Empty, + partitionKey: Guid.NewGuid().ToString(), new RedisFixedWindowRateLimiterOptions { PermitLimit = 1, @@ -65,7 +65,7 @@ public async Task ThrowsWhenAcquiringMoreThanLimit() public async Task CanAcquireAsyncResource() { using var limiter = new RedisFixedWindowRateLimiter( - "Test_CanAcquireAsyncResource_FW", + partitionKey: Guid.NewGuid().ToString(), new RedisFixedWindowRateLimiterOptions { PermitLimit = 1, diff --git a/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs b/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs index c07fa49..afc7b3f 100644 --- a/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs +++ b/test/RedisRateLimiting.Tests/UnitTests/SlidingWindowUnitTests.cs @@ -57,7 +57,7 @@ public void InvalidOptionsThrows() public async Task ThrowsWhenAcquiringMoreThanLimit() { var limiter = new RedisSlidingWindowRateLimiter( - string.Empty, + partitionKey: Guid.NewGuid().ToString(), new RedisSlidingWindowRateLimiterOptions { PermitLimit = 1, @@ -71,10 +71,8 @@ public async Task ThrowsWhenAcquiringMoreThanLimit() [Fact] public async Task CanAcquireAsyncResource() { - await Fixture.ClearStatisticsAsync("sw", "Test_CanAcquireAsyncResource_SW"); - using var limiter = new RedisSlidingWindowRateLimiter( - "Test_CanAcquireAsyncResource_SW", + partitionKey: Guid.NewGuid().ToString(), new RedisSlidingWindowRateLimiterOptions { PermitLimit = 1, @@ -104,7 +102,7 @@ public async Task CanAcquireAsyncResource() public async Task CanAcquireAsyncResourceWithSmallWindow() { using var limiter = new RedisSlidingWindowRateLimiter( - string.Empty, + partitionKey: Guid.NewGuid().ToString(), new RedisSlidingWindowRateLimiterOptions { PermitLimit = 1, diff --git a/test/RedisRateLimiting.Tests/UnitTests/TestFixture.cs b/test/RedisRateLimiting.Tests/UnitTests/TestFixture.cs index e1ec18c..af89941 100644 --- a/test/RedisRateLimiting.Tests/UnitTests/TestFixture.cs +++ b/test/RedisRateLimiting.Tests/UnitTests/TestFixture.cs @@ -23,13 +23,6 @@ public TestFixture() ConnectionMultiplexerFactory = () => ConnectionMultiplexer; } - public async Task ClearStatisticsAsync(string rl, string partitionKey) - { - var key = $"rl:{rl}:{{{partitionKey}}}:stats"; - var database = ConnectionMultiplexer.GetDatabase(); - await database.KeyDeleteAsync(key); - } - public void Dispose() { Dispose(true); diff --git a/test/RedisRateLimiting.Tests/UnitTests/TokenBucketUnitTests.cs b/test/RedisRateLimiting.Tests/UnitTests/TokenBucketUnitTests.cs index b44c586..acd9553 100644 --- a/test/RedisRateLimiting.Tests/UnitTests/TokenBucketUnitTests.cs +++ b/test/RedisRateLimiting.Tests/UnitTests/TokenBucketUnitTests.cs @@ -69,7 +69,7 @@ public void InvalidOptionsThrows() public async Task ThrowsWhenAcquiringMoreThanLimit() { var limiter = new RedisTokenBucketRateLimiter( - string.Empty, + partitionKey: Guid.NewGuid().ToString(), new RedisTokenBucketRateLimiterOptions { TokenLimit = 1, @@ -85,7 +85,7 @@ public async Task ThrowsWhenAcquiringMoreThanLimit() public async Task CanAcquireAsyncResource() { using var limiter = new RedisTokenBucketRateLimiter( - "Test_CanAcquireAsyncResource_TB", + partitionKey: Guid.NewGuid().ToString(), new RedisTokenBucketRateLimiterOptions { TokenLimit = 1,