raft: add isStateEqual test

This commit is contained in:
Xiang Li 2014-09-12 11:48:08 -07:00
parent f9ef453894
commit 0c09862494
2 changed files with 22 additions and 2 deletions

View File

@ -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 {

View File

@ -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++ {