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 pathrejoin_test.go
More file actions
57 lines (44 loc) · 1.48 KB
/
rejoin_test.go
File metadata and controls
57 lines (44 loc) · 1.48 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
package raftify
import (
"fmt"
"testing"
)
func TestToRejoin(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 Rejoin state
node.toRejoin()
if node.state != Rejoin {
t.Logf("Expected node to be in the Rejoin state, instead got %v", node.state.toString())
t.FailNow()
}
}
func TestRunRejoin(t *testing.T) {
// Reserve ports for this test
ports := reservePorts(2)
// Initialize and start dummy node
node1 := initDummyNode("TestNode_1", 1, 2, ports[0])
node2 := initDummyNode("TestNode_2", 2, 2, ports[1])
node1.createMemberlist()
defer node1.memberlist.Shutdown()
// Wait for the election timeout to elapse and the node to initiate a rejoin
node1.toRejoin()
node1.config.PeerList = []string{fmt.Sprintf("127.0.0.1:%v", node2.config.BindPort)}
node1.resetTimeout()
node1.runRejoin() // Returns because node1 can't join node2
// Start node2 for the second test with the rejoin and let it rejoin node1
node2.createMemberlist()
defer node2.memberlist.Shutdown()
node2.toRejoin()
node2.config.PeerList = []string{fmt.Sprintf("127.0.0.1:%v", node1.config.BindPort)}
node2.resetTimeout()
node2.runRejoin() // Joins node1 and switches into the Follower state
if node2.state != Follower {
t.Logf("Expected node to be in the Follower state, instead got: %v", node2.state.toString())
t.FailNow()
}
}