work work hard work
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using FluentAssertions;
|
||||
using StellaOps.Router.Gateway.RateLimit;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Router.Gateway.Tests;
|
||||
|
||||
public sealed class InstanceRateLimiterTests
|
||||
{
|
||||
[Fact]
|
||||
public void TryAcquire_ReportsMostConstrainedRuleWhenAllowed()
|
||||
{
|
||||
var limiter = new InstanceRateLimiter(
|
||||
[
|
||||
new RateLimitRule { PerSeconds = 300, MaxRequests = 2 },
|
||||
new RateLimitRule { PerSeconds = 30, MaxRequests = 1 },
|
||||
]);
|
||||
|
||||
var decision = limiter.TryAcquire("svc");
|
||||
|
||||
decision.Allowed.Should().BeTrue();
|
||||
decision.Scope.Should().Be(RateLimitScope.Instance);
|
||||
decision.WindowSeconds.Should().Be(30);
|
||||
decision.Limit.Should().Be(1);
|
||||
decision.CurrentCount.Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryAcquire_DeniesWhenAnyRuleIsExceeded()
|
||||
{
|
||||
var limiter = new InstanceRateLimiter(
|
||||
[
|
||||
new RateLimitRule { PerSeconds = 300, MaxRequests = 2 },
|
||||
new RateLimitRule { PerSeconds = 30, MaxRequests = 1 },
|
||||
]);
|
||||
|
||||
limiter.TryAcquire("svc").Allowed.Should().BeTrue();
|
||||
|
||||
var decision = limiter.TryAcquire("svc");
|
||||
|
||||
decision.Allowed.Should().BeFalse();
|
||||
decision.Scope.Should().Be(RateLimitScope.Instance);
|
||||
decision.WindowSeconds.Should().Be(30);
|
||||
decision.Limit.Should().Be(1);
|
||||
decision.RetryAfterSeconds.Should().BeGreaterThan(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user