mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
29 lines
547 B
Go
29 lines
547 B
Go
package ratelimit
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLimiterDisabled(t *testing.T) {
|
|
l := New(-1)
|
|
if err := l.Wait(context.Background()); err != nil {
|
|
t.Fatalf("Wait() error = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestLimiterContextCancel(t *testing.T) {
|
|
l := New(1)
|
|
if err := l.Wait(context.Background()); err != nil {
|
|
t.Fatalf("first Wait() error = %v", err)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Millisecond)
|
|
defer cancel()
|
|
|
|
if err := l.Wait(ctx); err == nil {
|
|
t.Fatalf("expected context error")
|
|
}
|
|
}
|