@@ -2,17 +2,30 @@ package core
22
33import (
44 "testing"
5+ "sync"
6+ "github.com/devfeel/dotweb/test"
57)
68
79// 以下为功能测试
810
911func Test_AddRequestCount_1 (t * testing.T ) {
10- var num uint64 = 1
11- var count uint64
12- for i := 0 ; i < 100 ; i ++ {
13- count = GlobalState .AddRequestCount (num )
12+ var wg sync.WaitGroup
13+ wg .Add (2 )
14+
15+ go addRequestCount (& wg ,50 )
16+
17+ go addRequestCount (& wg ,60 )
18+
19+ wg .Wait ()
20+
21+ test .Equal (t ,uint64 (110 ),GlobalState .TotalRequestCount )
22+ }
23+
24+ func addRequestCount (wg * sync.WaitGroup ,count int ) {
25+ for i := 0 ; i < count ; i ++ {
26+ GlobalState .AddRequestCount (1 )
1427 }
15- t . Log ( "TotalRequestCount:" , count )
28+ wg . Add ( - 1 )
1629}
1730
1831func Test_AddRequestCount_2 (t * testing.T ) {
@@ -26,12 +39,16 @@ func Test_AddRequestCount_2(t *testing.T) {
2639}
2740
2841func Test_AddErrorCount_1 (t * testing.T ) {
29- var num , count uint64
30- for i := 0 ; i < 100 ; i ++ {
31- num = 1
32- count = GlobalState .AddErrorCount (num )
33- }
34- t .Log ("TotalErrorCount:" , count )
42+ var wg sync.WaitGroup
43+ wg .Add (2 )
44+
45+ go addErrorCount (& wg ,50 )
46+
47+ go addErrorCount (& wg ,60 )
48+
49+ wg .Wait ()
50+
51+ test .Equal (t ,uint64 (110 ),GlobalState .TotalErrorCount )
3552}
3653
3754func Test_AddErrorCount_2 (t * testing.T ) {
@@ -43,6 +60,12 @@ func Test_AddErrorCount_2(t *testing.T) {
4360 t .Log ("TotalErrorCount:" , count )
4461}
4562
63+ func addErrorCount (wg * sync.WaitGroup ,count int ) {
64+ for i := 0 ; i < count ; i ++ {
65+ GlobalState .AddErrorCount (1 )
66+ }
67+ wg .Add (- 1 )
68+ }
4669// 以下是性能测试
4770
4871//基准测试
0 commit comments