blob: ef4c2b0823ccdd78c76caa9a942695476bf3f5f8 (
plain)
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
|
package metrics
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCounters(t *testing.T) {
var wg sync.WaitGroup
// Test IncrementIndeterminantDecisionsCount and IndeterminantDecisionsCountRef
IndeterminantDecisionsCount = 0
wg.Add(10)
for i := 0; i < 10; i++ {
go func() {
defer wg.Done()
IncrementIndeterminantDecisionsCount()
}()
}
wg.Wait()
assert.Equal(t, int64(10), *IndeterminantDecisionsCountRef())
// Test IncrementPermitDecisionsCount and PermitDecisionsCountRef
PermitDecisionsCount = 0
wg.Add(15)
for i := 0; i < 15; i++ {
go func() {
defer wg.Done()
IncrementPermitDecisionsCount()
}()
}
wg.Wait()
assert.Equal(t, int64(15), *PermitDecisionsCountRef())
// Test IncrementDenyDecisionsCount and DenyDecisionsCountRef
DenyDecisionsCount = 0
wg.Add(20)
for i := 0; i < 20; i++ {
go func() {
defer wg.Done()
IncrementDenyDecisionsCount()
}()
}
wg.Wait()
assert.Equal(t, int64(20), *DenyDecisionsCountRef())
// Test IncrementTotalErrorCount and TotalErrorCountRef
TotalErrorCount = 0
wg.Add(5)
for i := 0; i < 5; i++ {
go func() {
defer wg.Done()
IncrementTotalErrorCount()
}()
}
wg.Wait()
assert.Equal(t, int64(5), *TotalErrorCountRef())
}
|