mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1696 from xiang90/testnodetick
raft: add a test for node.Tick
This commit is contained in:
commit
b271e88c20
@ -192,6 +192,7 @@ type node struct {
|
||||
advancec chan struct{}
|
||||
tickc chan struct{}
|
||||
done chan struct{}
|
||||
stop chan struct{}
|
||||
}
|
||||
|
||||
func newNode() node {
|
||||
@ -204,11 +205,13 @@ func newNode() node {
|
||||
advancec: make(chan struct{}),
|
||||
tickc: make(chan struct{}),
|
||||
done: make(chan struct{}),
|
||||
stop: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (n *node) Stop() {
|
||||
close(n.done)
|
||||
n.stop <- struct{}{}
|
||||
<-n.stop
|
||||
}
|
||||
|
||||
func (n *node) run(r *raft) {
|
||||
@ -302,7 +305,9 @@ func (n *node) run(r *raft) {
|
||||
}
|
||||
r.raftLog.stableTo(prevLastUnstablei)
|
||||
advancec = nil
|
||||
case <-n.done:
|
||||
case <-n.stop:
|
||||
n.stop <- struct{}{}
|
||||
close(n.done)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -140,6 +140,20 @@ func TestBlockProposal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNodeTick ensures that node.Tick() will increase the
|
||||
// elapsed of the underly raft state machine.
|
||||
func TestNodeTick(t *testing.T) {
|
||||
n := newNode()
|
||||
r := newRaft(1, []uint64{1}, 10, 1)
|
||||
go n.run(r)
|
||||
elapsed := r.elapsed
|
||||
n.Tick()
|
||||
n.Stop()
|
||||
if r.elapsed != elapsed+1 {
|
||||
t.Errorf("elapsed = %d, want %d", r.elapsed, elapsed+1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadyContainUpdates(t *testing.T) {
|
||||
tests := []struct {
|
||||
rd Ready
|
||||
|
Loading…
x
Reference in New Issue
Block a user