raft: hide Campaign rules on applying all entries

This commit is contained in:
Xiang Li
2016-07-25 15:06:57 -07:00
parent ec5c5d9ddf
commit 484f579905
5 changed files with 60 additions and 37 deletions

View File

@@ -356,15 +356,12 @@ func TestNodeStart(t *testing.T) {
}
wants := []Ready{
{
SoftState: &SoftState{Lead: 1, RaftState: StateLeader},
HardState: raftpb.HardState{Term: 2, Commit: 2, Vote: 1},
HardState: raftpb.HardState{Term: 1, Commit: 1, Vote: 0},
Entries: []raftpb.Entry{
{Type: raftpb.EntryConfChange, Term: 1, Index: 1, Data: ccdata},
{Term: 2, Index: 2},
},
CommittedEntries: []raftpb.Entry{
{Type: raftpb.EntryConfChange, Term: 1, Index: 1, Data: ccdata},
{Term: 2, Index: 2},
},
},
{
@@ -384,7 +381,6 @@ func TestNodeStart(t *testing.T) {
}
n := StartNode(c, []Peer{{ID: 1}})
defer n.Stop()
n.Campaign(ctx)
g := <-n.Ready()
if !reflect.DeepEqual(g, wants[0]) {
t.Fatalf("#%d: g = %+v,\n w %+v", 1, g, wants[0])
@@ -393,6 +389,11 @@ func TestNodeStart(t *testing.T) {
n.Advance()
}
n.Campaign(ctx)
rd := <-n.Ready()
storage.Append(rd.Entries)
n.Advance()
n.Propose(ctx, []byte("foo"))
if g2 := <-n.Ready(); !reflect.DeepEqual(g2, wants[1]) {
t.Errorf("#%d: g = %+v,\n w %+v", 2, g2, wants[1])
@@ -507,10 +508,14 @@ func TestNodeAdvance(t *testing.T) {
}
n := StartNode(c, []Peer{{ID: 1}})
defer n.Stop()
rd := <-n.Ready()
storage.Append(rd.Entries)
n.Advance()
n.Campaign(ctx)
<-n.Ready()
n.Propose(ctx, []byte("foo"))
var rd Ready
select {
case rd = <-n.Ready():
t.Fatalf("unexpected Ready before Advance: %+v", rd)