github.com/sandwich-go/boost@v1.3.29/ratelimiter/ratelimit_test.go (about) 1 package ratelimiter 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 ) 8 9 func TestRateLimit(t *testing.T) { 10 rl := New(100) // per second, some slack. 11 12 rl.Take() // Initialize. 13 time.Sleep(time.Millisecond * 45) // Let some time pass. 14 15 prev := time.Now() 16 for i := 0; i < 10; i++ { 17 now := rl.Take() 18 if i > 0 { 19 fmt.Println(i, now.Sub(prev).Round(time.Millisecond*2)) 20 } 21 prev = now 22 } 23 }