Merge pull request #10891 from changkun/raft

raft/rafttest: simulate async send in node test
release-3.4
Xiang Li 2019-07-15 11:49:06 -07:00 committed by GitHub
commit 5a734e79f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -17,6 +17,7 @@ package rafttest
import (
"context"
"log"
"math/rand"
"sync"
"time"
@ -79,9 +80,14 @@ func (n *node) start() {
}
n.storage.Append(rd.Entries)
time.Sleep(time.Millisecond)
// TODO: make send async, more like real world...
// simulate async send, more like real world...
for _, m := range rd.Messages {
n.iface.send(m)
mlocal := m
go func() {
time.Sleep(time.Duration(rand.Int63n(10)) * time.Millisecond)
n.iface.send(mlocal)
}()
}
n.Advance()
case m := <-n.iface.recv():