From f2eb8560eda20bb7bd6f225b0569e6016f2663bb Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sun, 20 Nov 2016 21:59:28 -0800 Subject: [PATCH] raft: fix TestNodeProposeAddDuplicateNode Only send signal after applying conf change. Or deadlock might happen if raft node receives ready without conf change when the test server is slow. --- raft/node_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/raft/node_test.go b/raft/node_test.go index f88fc320f..f502b7c1b 100644 --- a/raft/node_test.go +++ b/raft/node_test.go @@ -303,7 +303,8 @@ func TestNodeProposeAddDuplicateNode(t *testing.T) { ticker := time.NewTicker(time.Millisecond * 100) done := make(chan struct{}) stop := make(chan struct{}) - applyChan := make(chan struct{}) + applyConfChan := make(chan struct{}) + go func() { defer close(done) for { @@ -322,25 +323,29 @@ func TestNodeProposeAddDuplicateNode(t *testing.T) { var cc raftpb.ConfChange cc.Unmarshal(e.Data) n.ApplyConfChange(cc) + applyConfChan <- struct{}{} } } n.Advance() - applyChan <- struct{}{} } } }() + cc1 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 1} ccdata1, _ := cc1.Marshal() n.ProposeConfChange(context.TODO(), cc1) - <-applyChan + <-applyConfChan + // try add the same node again n.ProposeConfChange(context.TODO(), cc1) - <-applyChan + <-applyConfChan + // the new node join should be ok cc2 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 2} ccdata2, _ := cc2.Marshal() n.ProposeConfChange(context.TODO(), cc2) - <-applyChan + <-applyConfChan + close(stop) <-done