-
Notifications
You must be signed in to change notification settings - Fork 17
/
turbo_bursty_limiter_test.go
53 lines (46 loc) · 1.04 KB
/
turbo_bursty_limiter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package turbo
import (
"testing"
"time"
)
func TestBurstyLimiter(t *testing.T) {
limiter, _ := NewBurstyLimiter(5, 10)
for i := 0; i < 30; i++ {
succ := limiter.Acquire()
if i < 5 && !succ {
t.Fail()
} else if !succ {
time.Sleep(100 * time.Millisecond)
succ = limiter.Acquire()
if !succ {
t.Fail()
return
}
t.Logf("TestBurstyLimiter|FAIL|RECOVER %d-------%v\n", i, succ)
} else {
t.Logf("TestBurstyLimiter %d-------%v\n", i, succ)
}
}
limiter.Destroy()
}
func TestBurstyLimiter2(t *testing.T) {
limiter, _ := NewBurstyLimiter(5, 1000)
succ := limiter.AcquireCount(5)
if !succ {
t.Fail()
}
t.Logf("TestBurstyLimiter2|AcquireCount|5|-------%v\n", succ)
for i := 0; i < 30; i++ {
succ := limiter.Acquire()
if i < 5 && succ {
t.Fail()
} else if i > 5 {
time.Sleep(1 * time.Millisecond)
succ = limiter.Acquire()
t.Logf("TestBurstyLimiter2|LEFT 5 |SUCC| %d-------%v\n", i, succ)
} else {
t.Logf("TestBurstyLimiter2|FIRST 5 |FAIL| %d-------%v\n", i, succ)
}
}
limiter.Destroy()
}