-
Notifications
You must be signed in to change notification settings - Fork 2
/
service_test.go
71 lines (60 loc) · 1.63 KB
/
service_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
package main
import (
"testing"
"time"
)
func TestBackgroundServiceChecks(t *testing.T) {
initGlobal("t/etc")
status := true
// Add, make sure it doesn't yet exist.
status = AddCheck("check_true", "gigo.com", 1)
if status != false {
t.Fatalf("AddCheck claims to have already started check_true / gigo.com")
}
t.Log("AddCheck(check_true, gigo.com) good")
// Add, make sure it did already exist (nearly a no-op)
status = AddCheck("check_true", "gigo.com", 1)
if status != true {
t.Fatalf("AddCheck claims we never started check_true / gigo.com")
}
t.Log("AddCheck(check_true, gigo.com) still good")
status = AddCheck("check_false", "gigo.com", 1)
status = AddCheck("check_false", "gigo.com", 1)
// Give it a chance to health check.
time.Sleep(time.Duration(2) * time.Second)
// Investigate health status.
status, _ = GetStatus("check_true", "gigo.com")
if status != true {
t.Fatalf("GetStatus(check_true,gigo.com) not yet true")
}
t.Log("GetStatus(check_true, gigo.com) good")
status, _ = GetStatus("check_false", "gigo.com")
if status != false {
t.Fatalf("GetStatus(check_false,gigo.com) not actually false")
}
t.Log("GetStatus(check_false, gigo.com) good")
}
func BenchmarkSetStatus(b *testing.B) {
initGlobal("t/etc")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
SetStatus("x", "y", true)
}
}
func BenchmarkGetStatus(b *testing.B) {
initGlobal("t/etc")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = GetStatus("x", "y")
}
}
func BenchmarkEmptyFunction(b *testing.B) {
initGlobal("t/etc")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
empty("x", "y", true)
}
}