-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_test.go
154 lines (118 loc) · 2.97 KB
/
stats_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package gonsq
import (
"testing"
)
func TestMessageCount(t *testing.T) {
counts := []uint64{
1, 2, 3, 4, 10, 100, 1000, 20000,
}
s := Stats{}
var counter uint64
for _, count := range counts {
counter += count
result := s.addMessageCount(count)
currentMessageCount := s.MessageCount()
if result != counter && result != currentMessageCount {
t.Fatalf("expecting counter of %d but got %d", counter, currentMessageCount)
}
}
}
func TestErrorCount(t *testing.T) {
counts := []uint64{
1, 2, 3, 4, 10, 100, 1000, 20000,
}
s := Stats{}
var counter uint64
for _, count := range counts {
counter += count
result := s.addErrorCount(count)
currentErrorCount := s.ErrorCount()
if result != counter && result != currentErrorCount {
t.Fatalf("expecting counter of %d but got %d", counter, currentErrorCount)
}
}
}
func TestStatsMessageInBuff(t *testing.T) {
counts := []int64{
1, 2, 3, 4, 10, 100, 1000, 20000,
}
s := Stats{}
var counter int64
for _, count := range counts {
counter += count
result := s.addMessageInBuffCount(count)
currentMessageInbuff := s.MessageInBuffer()
if result != counter && result != currentMessageInbuff {
t.Fatalf("expecting counter of %d but got %d", counter, currentMessageInbuff)
}
}
}
// func TestStatsThrottle(t *testing.T) {
// booleans := []bool{
// true, false, true, true, false, false, true,
// }
// s := Stats{}
// var b bool
// for _, boolean := range booleans {
// b = boolean
// s.setThrottle(boolean)
// if b != s.Throttle().Boolean() {
// t.Fatalf("expecting throttle value of %v but got %v", b, s.Throttle())
// }
// }
// }
func TestThrottleCount(t *testing.T) {
counts := []int64{
1, 2, 3, 4, 10, 100, 1000, 20000,
}
s := Stats{}
var counter int64
for _, count := range counts {
counter += count
result := s.addThrottleCount(count)
currentThrottleCount := s.ThrottleCount()
if result != counter && result != currentThrottleCount {
t.Fatalf("expecting counter of %d but got %d", counter, currentThrottleCount)
}
}
}
func TestStatsWorker(t *testing.T) {
x := 10
s := Stats{}
for i := 0; i < x; i++ {
s.addWorker(1)
}
if s.Worker() != int64(x) {
t.Fatalf("expecting worker %d but got %d", x, s.Worker())
}
for ; x > 0; x-- {
s.addWorker(-1)
}
if s.Worker() != 0 {
t.Fatal("expect worker to be 0")
}
}
func TestStatsConcurrency(t *testing.T) {
concurrencies := []int{
10, 50, 100, 500, 1000, 10000, 100000,
}
s := Stats{}
for _, concurrency := range concurrencies {
s.setConcurrency(concurrency)
if s.Concurrency() != concurrency {
t.Fatalf("expect %d concurrency but got %d", concurrency, s.Concurrency())
}
}
}
func TestStatsMaxInFlight(t *testing.T) {
maxInFlights := []int{
10, 50, 100, 500, 1000, 10000, 100000,
}
s := Stats{}
for _, maxInFlight := range maxInFlights {
s.setMaxInFlight(maxInFlight)
if s.MaxInFlight() != maxInFlight {
t.Fatalf("expect %d max in flight but got %d", maxInFlight, s.MaxInFlight())
}
}
}