mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-23 18:59:28 +00:00
fix: lint
This commit is contained in:
parent
d1ffeb7fb7
commit
340b82f7b6
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user