-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentry_test.go
68 lines (59 loc) · 1.31 KB
/
sentry_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
package sentry
import (
"sync"
"testing"
"time"
)
const TestCount = 21
func aggregatorToString(aggregator CollectorType) string {
switch aggregator {
case Sum:
return "sum"
case Avg:
return "avg"
case Max:
return "max"
case Min:
return "min"
default:
return ""
}
}
func testCollector(aggregator CollectorType, value float64) {
metric := "myapp_http_qps"
tags := map[string]string{
"from": "iOS",
"aggregator": aggregatorToString(aggregator),
}
collector := GetCollector(metric, tags, aggregator, 10)
collector.Put(value)
}
func TestAllCollectors(t *testing.T) {
for i := 0; i < TestCount; i++ {
testCollector(Sum, float64(i))
testCollector(Avg, float64(i))
testCollector(Max, float64(i))
testCollector(Min, float64(i))
time.Sleep(1 * time.Second)
}
}
func testInGoroutine(wg *sync.WaitGroup, aggregator CollectorType) {
defer wg.Done()
for i := 0; i < TestCount; i++ {
testCollector(aggregator, float64(i))
time.Sleep(1 * time.Second)
}
}
func TestAllCollectorsInGoroutine(t *testing.T) {
var wg sync.WaitGroup
wg.Add(4)
go testInGoroutine(&wg, Sum)
go testInGoroutine(&wg, Avg)
go testInGoroutine(&wg, Max)
go testInGoroutine(&wg, Min)
wg.Wait()
}
func TestGcCollector(t *testing.T) {
SetReportURL("http://127.0.0.1:51001/server/api/putMetrics")
startCollectGC("sdkApp")
}