-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathstats_test.go
More file actions
62 lines (50 loc) · 1.88 KB
/
Copy pathstats_test.go
File metadata and controls
62 lines (50 loc) · 1.88 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
package pinpoint
import (
"sync/atomic"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_drainStatsCountersSwapsAndResets(t *testing.T) {
resetResponseTime()
collectResponseTime(100)
collectResponseTime(200)
incrSampleNew()
incrUnSampleNew()
incrSampleCont()
incrUnSampleCont()
incrSkipNew()
incrSkipCont()
counters := drainStatsCounters()
assert.Equal(t, int64(300), counters.accResponseTime)
assert.Equal(t, int64(200), counters.maxResponseTime)
assert.Equal(t, int64(2), counters.requestCount)
assert.Equal(t, int64(1), counters.sampleNew)
assert.Equal(t, int64(1), counters.unSampleNew)
assert.Equal(t, int64(1), counters.sampleCont)
assert.Equal(t, int64(1), counters.unSampleCont)
assert.Equal(t, int64(1), counters.skipNew)
assert.Equal(t, int64(1), counters.skipCont)
assert.Equal(t, int64(0), atomic.LoadInt64(&accResponseTime))
assert.Equal(t, int64(0), atomic.LoadInt64(&maxResponseTime))
assert.Equal(t, int64(0), atomic.LoadInt64(&requestCount))
assert.Equal(t, int64(0), atomic.LoadInt64(&sampleNew))
assert.Equal(t, int64(0), atomic.LoadInt64(&unSampleNew))
assert.Equal(t, int64(0), atomic.LoadInt64(&sampleCont))
assert.Equal(t, int64(0), atomic.LoadInt64(&unSampleCont))
assert.Equal(t, int64(0), atomic.LoadInt64(&skipNew))
assert.Equal(t, int64(0), atomic.LoadInt64(&skipCont))
}
func Test_collectResponseTimePreservesMax(t *testing.T) {
resetResponseTime()
collectResponseTime(300)
collectResponseTime(100)
collectResponseTime(200)
counters := drainStatsCounters()
assert.Equal(t, int64(600), counters.accResponseTime)
assert.Equal(t, int64(3), counters.requestCount)
assert.Equal(t, int64(300), counters.maxResponseTime)
assert.Equal(t, int64(200), calcResponseAvg(counters.accResponseTime, counters.requestCount))
}
func Test_calcResponseAvgReturnsZeroWithoutRequests(t *testing.T) {
assert.Equal(t, int64(0), calcResponseAvg(100, 0))
}