瀏覽代碼

raft: fix test case, should wait config propose applied

Vincent Lee 9 年之前
父節點
當前提交
62bd5477b9
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      raft/node_test.go

+ 3 - 1
raft/node_test.go

@@ -325,13 +325,15 @@ func TestNodeProposeAddDuplicateNode(t *testing.T) {
 	cc1 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 1}
 	cc1 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 1}
 	ccdata1, _ := cc1.Marshal()
 	ccdata1, _ := cc1.Marshal()
 	n.ProposeConfChange(context.TODO(), cc1)
 	n.ProposeConfChange(context.TODO(), cc1)
+	time.Sleep(time.Millisecond * 10)
 	// try add the same node again
 	// try add the same node again
 	n.ProposeConfChange(context.TODO(), cc1)
 	n.ProposeConfChange(context.TODO(), cc1)
+	time.Sleep(time.Millisecond * 10)
 	// the new node join should be ok
 	// the new node join should be ok
 	cc2 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 2}
 	cc2 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 2}
 	ccdata2, _ := cc2.Marshal()
 	ccdata2, _ := cc2.Marshal()
 	n.ProposeConfChange(context.TODO(), cc2)
 	n.ProposeConfChange(context.TODO(), cc2)
-	time.Sleep(time.Second)
+	time.Sleep(time.Millisecond * 10)
 
 
 	if len(rdyEntries) != 4 {
 	if len(rdyEntries) != 4 {
 		t.Errorf("len(entry) = %d, want %d, %v\n", len(rdyEntries), 3, rdyEntries)
 		t.Errorf("len(entry) = %d, want %d, %v\n", len(rdyEntries), 3, rdyEntries)