Explorar o código

Merge pull request #6879 from xiang90/raft_test

raft: fix TestNodeProposeAddDuplicateNode
Xiang Li %!s(int64=9) %!d(string=hai) anos
pai
achega
d7c98a4695
Modificáronse 1 ficheiros con 10 adicións e 5 borrados
  1. 10 5
      raft/node_test.go

+ 10 - 5
raft/node_test.go

@@ -303,7 +303,8 @@ func TestNodeProposeAddDuplicateNode(t *testing.T) {
 	ticker := time.NewTicker(time.Millisecond * 100)
 	ticker := time.NewTicker(time.Millisecond * 100)
 	done := make(chan struct{})
 	done := make(chan struct{})
 	stop := make(chan struct{})
 	stop := make(chan struct{})
-	applyChan := make(chan struct{})
+	applyConfChan := make(chan struct{})
+
 	go func() {
 	go func() {
 		defer close(done)
 		defer close(done)
 		for {
 		for {
@@ -322,25 +323,29 @@ func TestNodeProposeAddDuplicateNode(t *testing.T) {
 						var cc raftpb.ConfChange
 						var cc raftpb.ConfChange
 						cc.Unmarshal(e.Data)
 						cc.Unmarshal(e.Data)
 						n.ApplyConfChange(cc)
 						n.ApplyConfChange(cc)
+						applyConfChan <- struct{}{}
 					}
 					}
 				}
 				}
 				n.Advance()
 				n.Advance()
-				applyChan <- struct{}{}
 			}
 			}
 		}
 		}
 	}()
 	}()
+
 	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)
-	<-applyChan
+	<-applyConfChan
+
 	// try add the same node again
 	// try add the same node again
 	n.ProposeConfChange(context.TODO(), cc1)
 	n.ProposeConfChange(context.TODO(), cc1)
-	<-applyChan
+	<-applyConfChan
+
 	// 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)
-	<-applyChan
+	<-applyConfChan
+
 	close(stop)
 	close(stop)
 	<-done
 	<-done