Skip to content

Commit

Permalink
Fix missing transaction ...again.
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulentropy committed Aug 12, 2024
1 parent 2f611a4 commit 6be762c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ratelimits/gcra.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ func maybeRefund(clk clock.Clock, txn Transaction, tat time.Time) *Decision {
if nowUnix > tatUnix {
// The TAT is in the past, therefore the bucket is full.
return &Decision{
allowed: false,
remaining: txn.limit.Burst,
retryIn: time.Duration(0),
resetIn: time.Duration(0),
newTAT: tat,
allowed: false,
remaining: txn.limit.Burst,
retryIn: time.Duration(0),
resetIn: time.Duration(0),
newTAT: tat,
transaction: txn,
}
}

Expand Down
2 changes: 2 additions & 0 deletions ratelimits/gcra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func TestMaybeRefund(t *testing.T) {
test.AssertEquals(t, d.remaining, int64(10))
test.AssertEquals(t, d.retryIn, time.Duration(0))
test.AssertEquals(t, d.resetIn, time.Duration(0))
// Transaction is set when our TAT is in the past.
test.AssertEquals(t, d.transaction, Transaction{"test", limit, 1, true, true})

// Spend 5 of our 10 requests, then refund 1.
d = maybeSpend(clk, Transaction{"test", limit, 5, true, true}, d.newTAT)
Expand Down

0 comments on commit 6be762c

Please sign in to comment.