This repository was archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreshutdown_test.go
More file actions
61 lines (49 loc) · 1.46 KB
/
preshutdown_test.go
File metadata and controls
61 lines (49 loc) · 1.46 KB
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
package raftify
import (
"fmt"
"testing"
)
func TestToPreShutdown(t *testing.T) {
// Reserve ports for this test
ports := reservePorts(1)
// Initialize and start dummy node
node := initDummyNode("TestNode", 1, 1, ports[0])
node.createMemberlist()
defer node.memberlist.Shutdown()
// Switch into Shutdown state
node.toPreShutdown()
if node.state != PreShutdown {
t.Logf("Expected node to be in the PreShutdown state, instead got %v", node.state.toString())
t.FailNow()
}
}
func TestRunPreShutdown(t *testing.T) {
// Reserve ports for this test
ports := reservePorts(2)
// Initialize and start dummy node
node1 := initDummyNode("TestNode_1", 2, 2, ports[0])
node2 := initDummyNode("TestNode_2", 2, 2, ports[1])
peerlist := []string{
fmt.Sprintf("127.0.0.1:%v", ports[0]),
fmt.Sprintf("127.0.0.1:%v", ports[1]),
}
node1.createMemberlist()
node2.createMemberlist()
defer node1.memberlist.Shutdown()
defer node2.memberlist.Shutdown()
// Form cluster
node1.memberlist.Join(peerlist)
// Run preshotdown with cluster size greater than 1 (2 in this case)
node1.runPreShutdown()
if node1.state != Shutdown {
t.Logf("Expected node1 to be in the Shutdown state, instead got %v", node1.state.toString())
t.FailNow()
}
// Run preshutdown with cluster size of 1
node2.memberlist.Shutdown()
node1.runPreShutdown()
if node1.state != Shutdown {
t.Logf("Expected node1 to be in the Shutdown state, instead got %v", node1.state.toString())
t.FailNow()
}
}