Skip to content

Commit

Permalink
Merge pull request etcd-io#10891 from changkun/raft
Browse files Browse the repository at this point in the history
raft/rafttest: simulate async send in node test
  • Loading branch information
xiang90 authored Jul 15, 2019
2 parents e56e847 + 8560971 commit 5a734e7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions raft/rafttest/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package rafttest
import (
"context"
"log"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 5a734e7

Please sign in to comment.