Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cristipufu committed Nov 13, 2023
1 parent 1dae76c commit b7c2c9d
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected override ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, C

protected override RateLimitLease AttemptAcquireCore(int permitCount)
{
// https://github.com/cristipufu/aspnetcore-redis-rate-limiting/issues/66
return FailedLease;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected override ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, C

protected override RateLimitLease AttemptAcquireCore(int permitCount)
{
// https://github.com/cristipufu/aspnetcore-redis-rate-limiting/issues/66
return FailedLease;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected override ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, C

protected override RateLimitLease AttemptAcquireCore(int permitCount)
{
// https://github.com/cristipufu/aspnetcore-redis-rate-limiting/issues/66
return FailedLease;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ protected override ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, C

protected override RateLimitLease AttemptAcquireCore(int permitCount)
{
// https://github.com/cristipufu/aspnetcore-redis-rate-limiting/issues/66
return FailedLease;
}

Expand Down
10 changes: 4 additions & 6 deletions test/RedisRateLimiting.Tests/UnitTests/ConcurrencyUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public async Task ThrowsWhenAcquiringMoreThanLimit()
QueueLimit = 1,
ConnectionMultiplexerFactory = Fixture.ConnectionMultiplexerFactory,
});
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => limiter.AttemptAcquire(2));
Assert.Equal("permitCount", ex.ParamName);
ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
var ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
Assert.Equal("permitCount", ex.ParamName);
}

Expand Down Expand Up @@ -89,7 +87,7 @@ public async Task CanAcquireAsyncResource()
Assert.Equal(1, stats.CurrentAvailablePermits);
}

[Fact]
[Fact(Skip = "Sync always returns failed lease")]
public void CanAcquireResource()
{
using var limiter = new RedisConcurrencyRateLimiter<string>(
Expand Down Expand Up @@ -161,7 +159,7 @@ public async Task FailsWhenQueuingMoreThanLimit()
ConnectionMultiplexerFactory = Fixture.ConnectionMultiplexerFactory,
});

using var lease = limiter.AttemptAcquire();
using var lease = await limiter.AcquireAsync();
var wait = limiter.AcquireAsync();

var failedLease = await limiter.AcquireAsync();
Expand All @@ -182,7 +180,7 @@ public async Task QueueAvailableAfterQueueLimitHitAndResourcesBecomeAvailable()
ConnectionMultiplexerFactory = Fixture.ConnectionMultiplexerFactory,
});

var lease = limiter.AttemptAcquire();
var lease = await limiter.AcquireAsync();
var wait = limiter.AcquireAsync();

await Task.Delay(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public async Task ThrowsWhenAcquiringMoreThanLimit()
Window = TimeSpan.FromMinutes(1),
ConnectionMultiplexerFactory = Fixture.ConnectionMultiplexerFactory,
});
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => limiter.AttemptAcquire(2));
Assert.Equal("permitCount", ex.ParamName);
ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
var ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
Assert.Equal("permitCount", ex.ParamName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public async Task ThrowsWhenAcquiringMoreThanLimit()
Window = TimeSpan.FromMinutes(1),
ConnectionMultiplexerFactory = Fixture.ConnectionMultiplexerFactory,
});
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => limiter.AttemptAcquire(2));
Assert.Equal("permitCount", ex.ParamName);
ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
var ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
Assert.Equal("permitCount", ex.ParamName);
}

Expand Down Expand Up @@ -110,7 +108,7 @@ public async Task CanAcquireAsyncResourceWithSmallWindow()
new RedisSlidingWindowRateLimiterOptions
{
PermitLimit = 1,
Window = TimeSpan.FromMilliseconds(100),
Window = TimeSpan.FromMilliseconds(600),
ConnectionMultiplexerFactory = Fixture.ConnectionMultiplexerFactory,
});

Expand All @@ -120,7 +118,7 @@ public async Task CanAcquireAsyncResourceWithSmallWindow()
using var lease2 = await limiter.AcquireAsync();
Assert.False(lease2.IsAcquired);

await Task.Delay(TimeSpan.FromMilliseconds(100));
await Task.Delay(TimeSpan.FromMilliseconds(600));

using var lease3 = await limiter.AcquireAsync();
Assert.True(lease3.IsAcquired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public async Task ThrowsWhenAcquiringMoreThanLimit()
ReplenishmentPeriod = TimeSpan.FromMinutes(1),
ConnectionMultiplexerFactory = Fixture.ConnectionMultiplexerFactory,
});
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => limiter.AttemptAcquire(2));
Assert.Equal("permitCount", ex.ParamName);
ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
var ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(async () => await limiter.AcquireAsync(2));
Assert.Equal("permitCount", ex.ParamName);
}

Expand Down

0 comments on commit b7c2c9d

Please sign in to comment.