mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: use the channel instead of sleep to make test case reliable
This commit is contained in:
parent
bc6f5ad53e
commit
e6d1ebcc1d
@ -303,6 +303,7 @@ func TestNodeProposeAddDuplicateNode(t *testing.T) {
|
||||
ticker := time.NewTicker(time.Millisecond * 100)
|
||||
done := make(chan struct{})
|
||||
stop := make(chan struct{})
|
||||
applyChan := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
for {
|
||||
@ -324,21 +325,22 @@ func TestNodeProposeAddDuplicateNode(t *testing.T) {
|
||||
}
|
||||
}
|
||||
n.Advance()
|
||||
applyChan <- struct{}{}
|
||||
}
|
||||
}
|
||||
}()
|
||||
cc1 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 1}
|
||||
ccdata1, _ := cc1.Marshal()
|
||||
n.ProposeConfChange(context.TODO(), cc1)
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
<-applyChan
|
||||
// try add the same node again
|
||||
n.ProposeConfChange(context.TODO(), cc1)
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
<-applyChan
|
||||
// the new node join should be ok
|
||||
cc2 := raftpb.ConfChange{Type: raftpb.ConfChangeAddNode, NodeID: 2}
|
||||
ccdata2, _ := cc2.Marshal()
|
||||
n.ProposeConfChange(context.TODO(), cc2)
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
<-applyChan
|
||||
close(stop)
|
||||
<-done
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user