/
app_stop_test.go
85 lines (64 loc) · 1.54 KB
/
app_stop_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
package carbon
import (
"os"
"runtime"
"runtime/pprof"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/signal18/replication-manager/graphite/qa"
)
func TestStartStop(t *testing.T) {
assert := assert.New(t)
startGoroutineNum := runtime.NumGoroutine()
for i := 0; i < 10; i++ {
qa.Root(t, func(root string) {
configFile := TestConfig(root)
app := New(configFile)
assert.NoError(app.ParseConfig())
assert.NoError(app.Start())
app.Stop()
})
}
endGoroutineNum := runtime.NumGoroutine()
// GC worker etc
if !assert.InDelta(startGoroutineNum, endGoroutineNum, 4) {
p := pprof.Lookup("goroutine")
p.WriteTo(os.Stdout, 1)
}
}
func TestReloadAndCollectorDeadlock(t *testing.T) {
//go func() {
// http.ListenAndServe("localhost:6060", nil)
//}()
qa.Root(t, func(root string) {
configFile := TestConfig(root)
app := New(configFile)
assert.NoError(t, app.ParseConfig())
app.Config.Common.MetricInterval = &Duration{time.Microsecond}
assert.NoError(t, app.Start())
reloadChan := make(chan struct{}, 1)
N := 1024
// start reload loop
go func() {
for i := N; i > 0; i-- {
app.ReloadConfig()
reloadChan <- struct{}{}
}
}()
ticker := time.NewTimer(0)
// goroutine doing reloadConfig should send N notifications if there were no deadlock
for rN := 0; rN < N; {
if !ticker.Stop() {
<-ticker.C
}
ticker.Reset(1 * time.Second)
select {
case <-reloadChan:
rN++
case <-ticker.C:
t.Fatalf("Collector and SIGHUP handers deadlocked")
}
}
})
}