forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boomer_test.go
64 lines (57 loc) · 1.33 KB
/
boomer_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
package boomer
import (
"os"
"testing"
"time"
)
func TestInitBoomer(t *testing.T) {
initBoomer()
defer Events.Unsubscribe("request_success", requestSuccessHandler)
defer Events.Unsubscribe("request_failure", requestFailureHandler)
defer defaultStats.close()
defer func() {
err := recover()
if err == nil {
t.Error("It should panic if initBoomer is called more than once.")
}
}()
initBoomer()
}
func TestRunTasksForTest(t *testing.T) {
count := 0
taskA := &Task{
Name: "increaseCount",
Fn: func() {
count++
},
}
runTasks = "increaseCount,foobar"
runTasksForTest(taskA)
if count != 1 {
t.Error("count is", count, "expected: 1")
}
}
func TestStartMemoryProfile(t *testing.T) {
if _, err := os.Stat("mem.pprof"); os.IsExist(err) {
os.Remove("mem.pprof")
}
startMemoryProfile("mem.pprof", 3*time.Second)
time.Sleep(4 * time.Second)
if _, err := os.Stat("mem.pprof"); os.IsNotExist(err) {
t.Error("File mem.pprof is not generated")
} else {
os.Remove("mem.pprof")
}
}
func TestStartCPUProfile(t *testing.T) {
if _, err := os.Stat("cpu.pprof"); os.IsExist(err) {
os.Remove("cpu.pprof")
}
startCPUProfile("cpu.pprof", 3*time.Second)
time.Sleep(4 * time.Second)
if _, err := os.Stat("cpu.pprof"); os.IsNotExist(err) {
t.Error("File cpu.pprof is not generated")
} else {
os.Remove("cpu.pprof")
}
}