Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion manager/state/raft/membership/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ func TestCanRemoveMember(t *testing.T) {

// Add back node 3
raftutils.ShutdownNode(nodes[3])
delete(nodes, 3)
nodes[3] = raftutils.NewJoinNode(t, clockSource, nodes[leader].Address, tc)
raftutils.WaitForCluster(t, clockSource, nodes)

Expand Down
41 changes: 10 additions & 31 deletions manager/state/raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,20 +685,15 @@ func TestRaftForceNewCluster(t *testing.T) {
assert.Len(t, nodes[uint64(i)].GetMemberlist(), 3)
}

// Stop all nodes
for _, node := range nodes {
node.Server.Stop()
node.ShutdownRaft()
}
// Stop the first node, and remove the second and third one.
nodes[1].Server.Stop()
nodes[1].ShutdownRaft()

raftutils.AdvanceTicks(clockSource, 5)

toClean := map[uint64]*raftutils.TestNode{
2: nodes[2],
3: nodes[3],
}
raftutils.TeardownCluster(toClean)
raftutils.ShutdownNode(nodes[2])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the for loop above only needs to act on node 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the above for loop to just shutdown the first node.

delete(nodes, 2)
raftutils.ShutdownNode(nodes[3])
delete(nodes, 3)

// Only restart the first node with force-new-cluster option
Expand All @@ -708,19 +703,9 @@ func TestRaftForceNewCluster(t *testing.T) {
// The memberlist should contain only one node (self)
assert.Len(t, nodes[1].GetMemberlist(), 1)

// Add 2 more members
nodes[2] = raftutils.NewJoinNode(t, clockSource, nodes[1].Address, tc)
raftutils.WaitForCluster(t, clockSource, nodes)

nodes[3] = raftutils.NewJoinNode(t, clockSource, nodes[1].Address, tc)
raftutils.WaitForCluster(t, clockSource, nodes)

newCluster := map[uint64]*raftutils.TestNode{
1: nodes[1],
2: nodes[2],
3: nodes[3],
}
defer raftutils.TeardownCluster(newCluster)
// Replace the other 2 members
raftutils.AddRaftNode(t, clockSource, nodes, tc)
raftutils.AddRaftNode(t, clockSource, nodes, tc)

// The memberlist should contain 3 members on each node
for i := 1; i <= 3; i++ {
Expand Down Expand Up @@ -762,18 +747,12 @@ func TestRaftUnreachableNode(t *testing.T) {
t.Parallel()

nodes := make(map[uint64]*raftutils.TestNode)
defer raftutils.TeardownCluster(nodes)
var clockSource *fakeclock.FakeClock
nodes[1], clockSource = raftutils.NewInitNode(t, tc, nil)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Add a new node
nodes[2] = raftutils.NewNode(t, clockSource, tc, raft.NodeOptions{JoinAddr: nodes[1].Address})

err := nodes[2].JoinAndStart(ctx)
require.NoError(t, err, "can't join cluster")

go nodes[2].Run(ctx)
raftutils.AddRaftNode(t, clockSource, nodes, tc, raft.NodeOptions{JoinAddr: nodes[1].Address})

// Stop the Raft server of second node on purpose after joining
nodes[2].Server.Stop()
Expand Down
4 changes: 1 addition & 3 deletions manager/state/raft/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ func TestRaftSnapshotForceNewCluster(t *testing.T) {
nodes[1].Server.Stop()
nodes[1].ShutdownRaft()
nodes[1] = raftutils.RestartNode(t, clockSource, nodes[1], true)
delete(nodes, 3)
delete(nodes, 4)
raftutils.WaitForCluster(t, clockSource, nodes)
raftutils.WaitForCluster(t, clockSource, map[uint64]*raftutils.TestNode{1: nodes[1]})

// The memberlist should contain exactly one node (self)
memberlist := nodes[1].GetMemberlist()
Expand Down
2 changes: 1 addition & 1 deletion manager/state/raft/testutils/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func NewNode(t *testing.T, clockSource *fakeclock.FakeClock, tc *cautils.TestCA,

cfg := raft.DefaultNodeConfig()

stateDir, err := ioutil.TempDir("", "test-raft")
stateDir, err := ioutil.TempDir("", t.Name())
require.NoError(t, err, "can't create temporary state directory")

keyRotator := NewSimpleKeyRotator(raft.EncryptionKeys{CurrentDEK: []byte("current")})
Expand Down