2019-11-25 09:23:04 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
2019-11-26 03:28:16 +00:00
|
|
|
"fmt"
|
2019-11-25 09:23:04 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLimiter(t *testing.T) {
|
|
|
|
limiter := NewLimiterServer(1*time.Second, 5)
|
|
|
|
|
|
|
|
for {
|
|
|
|
if limiter.IsAvailable() {
|
|
|
|
t.Log("hello...", limiter.reqCount)
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-26 03:28:16 +00:00
|
|
|
|
|
|
|
func TestLimiter2(t *testing.T) {
|
|
|
|
limiter := NewLimiterServer(10*time.Second, 10)
|
|
|
|
|
|
|
|
for i := 0; i < 20; i++ {
|
|
|
|
if limiter.IsAvailable() {
|
|
|
|
fmt.Println("hello...", limiter.reqCount)
|
|
|
|
} else {
|
|
|
|
fmt.Println("limited")
|
|
|
|
}
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
}
|