mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raftexample: Add test for adding new node to existing cluster
This commit is contained in:
parent
1b1be43d65
commit
cb0d256a18
@ -205,3 +205,39 @@ func TestPutAndGetKeyValue(t *testing.T) {
|
|||||||
t.Fatalf("expect %s, got %s", wantValue, gotValue)
|
t.Fatalf("expect %s, got %s", wantValue, gotValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAddNewNode tests adding new node to the existing cluster.
|
||||||
|
func TestAddNewNode(t *testing.T) {
|
||||||
|
clus := newCluster(3)
|
||||||
|
defer clus.closeNoErrors(t)
|
||||||
|
|
||||||
|
os.RemoveAll("raftexample-4")
|
||||||
|
os.RemoveAll("raftexample-4-snap")
|
||||||
|
defer func() {
|
||||||
|
os.RemoveAll("raftexample-4")
|
||||||
|
os.RemoveAll("raftexample-4-snap")
|
||||||
|
}()
|
||||||
|
|
||||||
|
newNodeURL := "http://127.0.0.1:10004"
|
||||||
|
clus.confChangeC[0] <- raftpb.ConfChange{
|
||||||
|
Type: raftpb.ConfChangeAddNode,
|
||||||
|
NodeID: 4,
|
||||||
|
Context: []byte(newNodeURL),
|
||||||
|
}
|
||||||
|
|
||||||
|
proposeC := make(chan string)
|
||||||
|
defer close(proposeC)
|
||||||
|
|
||||||
|
confChangeC := make(chan raftpb.ConfChange)
|
||||||
|
defer close(confChangeC)
|
||||||
|
|
||||||
|
newRaftNode(4, append(clus.peers, newNodeURL), true, nil, proposeC, confChangeC)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
proposeC <- "foo"
|
||||||
|
}()
|
||||||
|
|
||||||
|
if c, ok := <-clus.commitC[0]; !ok || c.data[0] != "foo" {
|
||||||
|
t.Fatalf("Commit failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user