TestProposal

Don't check on `committed` but `lastIndex` instead.

Signed-off-by: Tobias Grieger <tobias.b.grieger@gmail.com>
This commit is contained in:
Tobias Grieger 2022-09-06 12:22:37 +02:00
parent 15abe294e7
commit ff837f3a0b
2 changed files with 5 additions and 5 deletions

View File

@ -55,7 +55,7 @@ func mustTemp(pre, body string) string {
} }
func ltoa(l *raftLog) 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) s += fmt.Sprintf("applied: %d\n", l.applied)
for i, e := range l.allEntries() { for i, e := range l.allEntries() {
s += fmt.Sprintf("#%d: %+v\n", i, e) s += fmt.Sprintf("#%d: %+v\n", i, e)

View File

@ -1077,6 +1077,7 @@ func TestProposal(t *testing.T) {
// promote 1 to become leader // promote 1 to become leader
send(pb.Message{From: 1, To: 1, Type: pb.MsgHup}) 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}}}) 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) wantLog := newLog(NewMemoryStorage(), raftLogger)
if tt.success { if tt.success {
@ -1084,8 +1085,8 @@ func TestProposal(t *testing.T) {
storage: &MemoryStorage{ storage: &MemoryStorage{
ents: []pb.Entry{{}, {Data: nil, Term: 1, Index: 1}, {Term: 1, Index: 2, Data: data}}, ents: []pb.Entry{{}, {Data: nil, Term: 1, Index: 1}, {Term: 1, Index: 2, Data: data}},
}, },
unstable: unstable{offset: 3}, unstable: unstable{offset: 3},
committed: 2} }
} }
base := ltoa(wantLog) base := ltoa(wantLog)
for i, p := range tt.peers { for i, p := range tt.peers {
@ -1098,8 +1099,7 @@ func TestProposal(t *testing.T) {
t.Logf("#%d: peer %d empty log", j, i) t.Logf("#%d: peer %d empty log", j, i)
} }
} }
sm := tt.network.peers[1].(*raft) if g := r.Term; g != 1 {
if g := sm.Term; g != 1 {
t.Errorf("#%d: term = %d, want %d", j, g, 1) t.Errorf("#%d: term = %d, want %d", j, g, 1)
} }
} }