mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add isStateEqual test
This commit is contained in:
parent
f9ef453894
commit
0c09862494
@ -35,7 +35,7 @@ type Ready struct {
|
||||
}
|
||||
|
||||
func isStateEqual(a, b pb.State) bool {
|
||||
return a.Term == b.Term && a.Vote == b.Vote && a.LastIndex == b.LastIndex
|
||||
return a.Term == b.Term && a.Vote == b.Vote && a.Commit == b.Commit && a.LastIndex == b.LastIndex
|
||||
}
|
||||
|
||||
func IsEmptyState(st pb.State) bool {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/raft/raftpb"
|
||||
"github.com/coreos/etcd/third_party/code.google.com/p/go.net/context"
|
||||
@ -82,7 +83,7 @@ func TestNodeStepUnblock(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestBlockProposal ensures that node will block proposal when it does not
|
||||
// know who is the current leader; node will direct proposal when it knows
|
||||
// know who is the current leader; node will accept proposal when it knows
|
||||
// who is the current leader.
|
||||
func TestBlockProposal(t *testing.T) {
|
||||
n := newNode()
|
||||
@ -193,6 +194,25 @@ func TestNodeRestart(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsStateEqual(t *testing.T) {
|
||||
tests := []struct {
|
||||
st raftpb.State
|
||||
we bool
|
||||
}{
|
||||
{emptyState, true},
|
||||
{raftpb.State{Vote: 1}, false},
|
||||
{raftpb.State{Commit: 1}, false},
|
||||
{raftpb.State{Term: 1}, false},
|
||||
{raftpb.State{LastIndex: 1}, false},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
if isStateEqual(tt.st, emptyState) != tt.we {
|
||||
t.Errorf("#%d, equal = %v, want %v", i, isStateEqual(tt.st, emptyState), tt.we)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mustEnoughSched() {
|
||||
// possibility enough to sched upto 10 go routines.
|
||||
for i := 0; i < 10000; i++ {
|
||||
|
Loading…
x
Reference in New Issue
Block a user