-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduoo_test.go
116 lines (104 loc) · 2.22 KB
/
duoo_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package duoo
import (
"fmt"
"sync"
"testing"
"time"
"github.com/Tokeniso/duoo/emitter"
"github.com/Tokeniso/duoo/tool"
)
// 布尔速率许可分配测试
func TestRateStartWithDebug(t *testing.T) {
bc := RateStartWithDebug(50000000, 1)
wg := sync.WaitGroup{}
for i := 0; i < 30000; i++ {
wg.Add(1)
go func() {
defer func() {
wg.Done()
}()
for j := 0; j < 5000000; j++ {
_, err := bc.GetPermission()
if err != nil {
//t.Logf("err: %s", err)
break
}
}
}()
}
time.AfterFunc(9011*time.Millisecond, func() {
bc.Stop()
})
wg.Wait()
for key, val := range bc.Count {
t.Logf("循环批次:%d -- wait:%d -- retry:%d -- done:%d -- make:%d\n",
key, val.Wait, val.Retry, val.Done, val.Make)
}
}
// 布尔速率许可分配测试
func TestRateStart(t *testing.T) {
bc := RateStart(300000, 1)
wg := sync.WaitGroup{}
mu := sync.Mutex{}
for i := 0; i < 30000; i++ {
wg.Add(1)
go func() {
defer func() {
wg.Done()
}()
for j := 0; j < 50000; j++ {
_, err := bc.GetPermission()
if err != nil {
//t.Logf("err: %s", err)
break
}
tag := bc.GetTag()
mu.Lock()
_, ok := bc.Count[tag]
if !ok {
bc.Count[tag] = &tool.Statistics{0, 0, 0, 0}
}
bc.Count[tag].Done++
mu.Unlock()
}
}()
}
time.AfterFunc(4011*time.Millisecond, func() {
bc.Stop()
})
wg.Wait()
for key, val := range bc.Count {
t.Logf("循环批次:%d -- wait:%d -- retry:%d -- done:%d -- make:%d\n",
key, val.Wait, val.Retry, val.Done, val.Make)
}
}
// 唯一ID速率许可分配测试
func TestStartEmitterWithDebug(t *testing.T) {
ei := emitter.UniqIdEmitter{}
bc := StartEmitterWithDebug(50000000, 1, &ei)
wg := sync.WaitGroup{}
for i := 0; i < 30000; i++ {
wg.Add(1)
go func() {
defer func() {
wg.Done()
}()
for j := 0; j < 5000000; j++ {
a, err := bc.GetPermission()
fmt.Println(a)
if err != nil {
//t.Logf("err: %s", err)
break
}
}
}()
}
time.AfterFunc(9011*time.Millisecond, func() {
bc.Stop()
})
wg.Wait()
for key, val := range bc.Count {
t.Logf("循环批次:%d -- wait:%d -- retry:%d -- done:%d -- make:%d\n",
key, val.Wait, val.Retry, val.Done, val.Make)
}
}