fix: lint

This commit is contained in:
pablo 2025-07-07 09:00:41 +03:00
parent d1ffeb7fb7
commit 340b82f7b6
2 changed files with 12 additions and 10 deletions

View File

@ -122,7 +122,8 @@ suite "Token Bucket":
# Test with minimal usage - less consumption means less compensation # Test with minimal usage - less consumption means less compensation
bucket = TokenBucket.new(1000, 1.minutes, ReplenishMode.Compensating) bucket = TokenBucket.new(1000, 1.minutes, ReplenishMode.Compensating)
reqTime = Moment.now() reqTime = Moment.now()
check bucket.tryConsume(50, reqTime) == true # Use only 5% of capacity (950 remaining) check bucket.tryConsume(50, reqTime) == true
# Use only 5% of capacity (950 remaining)
# Move to next period - compensation based on remaining budget # Move to next period - compensation based on remaining budget
# UsageAverage = 950/1000/1.0 = 0.95, so compensation = (1.0-0.95)*1000 = 50 # UsageAverage = 950/1000/1.0 = 0.95, so compensation = (1.0-0.95)*1000 = 50
@ -140,4 +141,3 @@ suite "Token Bucket":
reqTime += 1.minutes reqTime += 1.minutes
let (maxCompensationBudget, _) = bucket.getAvailableCapacity(reqTime) let (maxCompensationBudget, _) = bucket.getAvailableCapacity(reqTime)
check maxCompensationBudget == 1250 # 1000 + 250 max compensation check maxCompensationBudget == 1250 # 1000 + 250 max compensation

View File

@ -110,7 +110,9 @@ proc update(bucket: TokenBucket, currentTime: Moment) =
updateStrict(bucket, currentTime) updateStrict(bucket, currentTime)
## Returns the available capacity of the bucket: (budget, budgetCap) ## Returns the available capacity of the bucket: (budget, budgetCap)
proc getAvailableCapacity*(bucket: TokenBucket, currentTime: Moment = Moment.now()): tuple[budget: int, budgetCap: int] = proc getAvailableCapacity*(
bucket: TokenBucket, currentTime: Moment = Moment.now()
): tuple[budget: int, budgetCap: int] =
if periodElapsed(bucket, currentTime): if periodElapsed(bucket, currentTime):
case bucket.replenishMode case bucket.replenishMode
of ReplenishMode.Strict: of ReplenishMode.Strict: