-
Notifications
You must be signed in to change notification settings - Fork 1
/
phi_test.go
57 lines (44 loc) · 1.05 KB
/
phi_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
package failuredetector
import (
"testing"
"time"
)
func createFailureDetector(c clock) *PhiAccuralFailureDetector {
res, err := New(
8.0,
1000,
10*time.Millisecond,
0,
1*time.Second,
nil)
if err != nil {
panic(err)
}
res.clock = c
return res
}
func TestNodeIsAvailableAfterASeriesOfSuccessfulHeartbeats(t *testing.T) {
timeInterval := []int{0, 1000, 100, 100}
fd := createFailureDetector(newFakeClock(timeInterval))
fd.Heartbeat()
fd.Heartbeat()
fd.Heartbeat()
if !fd.IsAvailable() {
t.Error("detector should report resource available")
}
}
func TestNodeMarkedDeadAfterHeartbeatsAreMissed(t *testing.T) {
timeInterval := []int{0, 1000, 100, 100, 4000, 3000}
fd := createFailureDetector(newFakeClock(timeInterval))
fd.threshold = 3.0
fd.Heartbeat() //0
fd.Heartbeat() //1000
fd.Heartbeat() //1100
if !fd.IsAvailable() { //1200
t.Error("detector should report resource available")
}
fd.clock() //5200, but unrelated resource
if fd.IsAvailable() { //1200
t.Error("detector shouldn't report resource available")
}
}