Skip to content

Commit

Permalink
TestProposal
Browse files Browse the repository at this point in the history
Don't check on `committed` but `lastIndex` instead.

Signed-off-by: Tobias Grieger <tobias.b.grieger@gmail.com>
  • Loading branch information
tbg committed Sep 20, 2022
1 parent 15abe29 commit ff837f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion raft/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func mustTemp(pre, body string) string {
}

func ltoa(l *raftLog) string {
s := fmt.Sprintf("committed: %d\n", l.committed)
s := fmt.Sprintf("lastIndex: %d\n", l.lastIndex())
s += fmt.Sprintf("applied: %d\n", l.applied)
for i, e := range l.allEntries() {
s += fmt.Sprintf("#%d: %+v\n", i, e)
Expand Down
8 changes: 4 additions & 4 deletions raft/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,15 +1077,16 @@ func TestProposal(t *testing.T) {
// promote 1 to become leader
send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})
send(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: data}}})
r := tt.network.peers[1].(*raft)

wantLog := newLog(NewMemoryStorage(), raftLogger)
if tt.success {
wantLog = &raftLog{
storage: &MemoryStorage{
ents: []pb.Entry{{}, {Data: nil, Term: 1, Index: 1}, {Term: 1, Index: 2, Data: data}},
},
unstable: unstable{offset: 3},
committed: 2}
unstable: unstable{offset: 3},
}
}
base := ltoa(wantLog)
for i, p := range tt.peers {
Expand All @@ -1098,8 +1099,7 @@ func TestProposal(t *testing.T) {
t.Logf("#%d: peer %d empty log", j, i)
}
}
sm := tt.network.peers[1].(*raft)
if g := sm.Term; g != 1 {
if g := r.Term; g != 1 {
t.Errorf("#%d: term = %d, want %d", j, g, 1)
}
}
Expand Down

0 comments on commit ff837f3

Please sign in to comment.