-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathstate_test.go
More file actions
123 lines (98 loc) · 2.37 KB
/
state_test.go
File metadata and controls
123 lines (98 loc) · 2.37 KB
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
117
118
119
120
121
122
123
package core
import (
"errors"
"github.com/devfeel/dotweb/test"
"sync"
"testing"
)
// 以下为功能测试
func Test_AddRequestCount_1(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
go addRequestCount(&wg, 50)
go addRequestCount(&wg, 60)
wg.Wait()
test.Equal(t, uint64(110), GlobalState.TotalRequestCount)
}
func addRequestCount(wg *sync.WaitGroup, count int) {
for i := 0; i < count; i++ {
GlobalState.AddRequestCount("test", 200, 1)
}
wg.Add(-1)
}
func Test_CurrentRequestCount(t *testing.T) {
//var num uint64 = 1
GlobalState.AddCurrentRequest(1000465)
t.Log(GlobalState.CurrentRequestCount)
GlobalState.SubCurrentRequest(2561)
t.Log(GlobalState.CurrentRequestCount)
}
func Test_AddRequestCount_2(t *testing.T) {
var num uint64 = 1
for i := 0; i < 100; i++ {
GlobalState.AddRequestCount("test", 200, num)
num++
}
}
func Test_AddErrorCount_1(t *testing.T) {
var wg sync.WaitGroup
wg.Add(2)
go addErrorCount(&wg, 50)
go addErrorCount(&wg, 60)
wg.Wait()
test.Equal(t, uint64(110), GlobalState.TotalErrorCount)
}
func Test_AddErrorCount_2(t *testing.T) {
var num, count uint64
for i := 0; i < 100; i++ {
count = GlobalState.AddErrorCount("test", errors.New("test error"), num)
num++
}
t.Log("TotalErrorCount:", count)
}
func addErrorCount(wg *sync.WaitGroup, count int) {
for i := 0; i < count; i++ {
GlobalState.AddErrorCount("test", errors.New("test error"), 1)
}
wg.Add(-1)
}
// 以下是性能测试
//基准测试
func Benchmark_AddErrorCount_1(b *testing.B) {
var num uint64 = 1
for i := 0; i < b.N; i++ {
GlobalState.AddErrorCount("test", errors.New("test error"), num)
}
}
// 测试并发效率
func Benchmark_AddErrorCount_Parallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var num uint64 = 1
for pb.Next() {
GlobalState.AddErrorCount("test", errors.New("test error"), num)
}
})
}
//基准测试
func Benchmark_AddRequestCount_1(b *testing.B) {
var num uint64 = 1
for i := 0; i < b.N; i++ {
GlobalState.AddRequestCount("test", 200, num)
}
}
//基准测试
func Benchmark_AddCurrentRequestCount_1(b *testing.B) {
var num uint64 = 1
for i := 0; i < b.N; i++ {
GlobalState.AddCurrentRequest(num)
}
}
// 测试并发效率
func Benchmark_AddRequestCount_Parallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var num uint64 = 1
for pb.Next() {
GlobalState.AddRequestCount("test", 200, num)
}
})
}