(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
func TestRateLimiterCheckDropOverflowHonorsGlobalLock(t *testing.T) {
|
||||
@@ -28,6 +30,25 @@ func TestRateLimiterChatLocksAreScopedPerChat(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateLimiterRejectedChatDoesNotConsumeGlobalCapacity(t *testing.T) {
|
||||
rl := NewRateLimiter()
|
||||
rl.SetGlobalRate(1)
|
||||
|
||||
if !rl.Allow(42) {
|
||||
t.Fatal("expected initial request for chat 42 to succeed")
|
||||
}
|
||||
rl.globalMu.Lock()
|
||||
rl.globalLimiter = rate.NewLimiter(1, 1)
|
||||
rl.globalMu.Unlock()
|
||||
|
||||
if rl.Allow(42) {
|
||||
t.Fatal("expected exhausted chat limiter to reject the request")
|
||||
}
|
||||
if !rl.Allow(7) {
|
||||
t.Fatal("expected rejected chat request not to consume global capacity")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateLimiterGlobalWaitRespectsContextCancellation(t *testing.T) {
|
||||
rl := NewRateLimiter()
|
||||
rl.SetGlobalLock(1)
|
||||
|
||||
Reference in New Issue
Block a user