From ff837f3a0b47a7c13c881de563ed4425350c585e Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Tue, 6 Sep 2022 12:22:37 +0200 Subject: [PATCH] TestProposal Don't check on `committed` but `lastIndex` instead. Signed-off-by: Tobias Grieger --- raft/diff_test.go | 2 +- raft/raft_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/raft/diff_test.go b/raft/diff_test.go index 3114a1f0017..6030527941f 100644 --- a/raft/diff_test.go +++ b/raft/diff_test.go @@ -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) diff --git a/raft/raft_test.go b/raft/raft_test.go index 17070f8f1d1..c4d005d7c0e 100644 --- a/raft/raft_test.go +++ b/raft/raft_test.go @@ -1077,6 +1077,7 @@ 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 { @@ -1084,8 +1085,8 @@ func TestProposal(t *testing.T) { 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 { @@ -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) } }