- access frequence limit
- output detail request when error
This commit is contained in:
40
platformapi/limit_access_speed_test.go
Normal file
40
platformapi/limit_access_speed_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package platformapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestLimitSpeed(t *testing.T) {
|
||||
limiter := New(map[string]*LimiterConfig{
|
||||
"limited1persecond": &LimiterConfig{
|
||||
MaxAccessCount: 1,
|
||||
TimeGapInSecond: 1,
|
||||
},
|
||||
"limited10per10second": &LimiterConfig{
|
||||
MaxAccessCount: 10,
|
||||
TimeGapInSecond: 10,
|
||||
},
|
||||
})
|
||||
|
||||
go func() {
|
||||
count := 0
|
||||
for {
|
||||
limiter.AccessAPI("limited1persecond")
|
||||
fmt.Printf("limited1persecond, time:%s, count:%d\n", utils.GetCurTimeStr(), count)
|
||||
count++
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
count := 0
|
||||
for {
|
||||
limiter.AccessAPI("limited10per10second")
|
||||
fmt.Printf("limited10per10second, time:%s, count:%d\n", utils.GetCurTimeStr(), count)
|
||||
count++
|
||||
}
|
||||
}()
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
Reference in New Issue
Block a user