forked from Syncano/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 197
/
pprof_test.go
57 lines (49 loc) · 1.52 KB
/
pprof_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
//go:build pprof
// +build pprof
package main
import (
"fmt"
"os"
"testing"
"time"
"github.com/kbudde/rabbitmq_exporter/testenv"
)
func TestPProf(t *testing.T) {
// go test -v -run TestPProf -tags pprof -cpuprofile=cpuprof.out
// go-torch rabbitmq_exporter.test cpuprof.out
var env testenv.TestEnvironment
var exporterURL string
var rabbitManagementURL string
t.Run("Preparation", func(t *testing.T) {
env = testenv.NewEnvironment(t, testenv.RabbitMQ3Latest)
exporterURL = fmt.Sprintf("http://localhost:%s/metrics", defaultConfig.PublishPort)
rabbitManagementURL = env.ManagementURL()
os.Setenv("LOG_LEVEL", "FATAL")
defer os.Unsetenv("LOG_LEVEL")
go main()
for i := 0; i < 100; i++ {
queue := fmt.Sprintf("queue-%d", i)
env.Rabbit.DeclareQueue(queue, false)
}
time.Sleep(5 * time.Second) // give rabbitmq management plugin a bit of time
})
defer env.CleanUp() // do not panic or exit fatally or the container will stay up
os.Setenv("RABBIT_URL", rabbitManagementURL)
defer os.Unsetenv("RABBIT_URL")
t.Run("Fetch Exporter Bert, no sort", func(t *testing.T) {
os.Setenv("RABBIT_CAPABILITIES", "bert,no_sort")
defer os.Unsetenv("RABBIT_CAPABILITIES")
initConfig()
for i := 0; i < 100; i++ {
testenv.GetOrDie(exporterURL, 5*time.Second)
}
})
t.Run("Fetch Exporter Json, no sort", func(t *testing.T) {
os.Setenv("RABBIT_CAPABILITIES", "no_sort")
defer os.Unsetenv("RABBIT_CAPABILITIES")
initConfig()
for i := 0; i < 100; i++ {
testenv.GetOrDie(exporterURL, 5*time.Second)
}
})
}