diff --git a/raft/log_test.go b/raft/log_test.go index 6f9a6cd57c02..58a87af2ef67 100644 --- a/raft/log_test.go +++ b/raft/log_test.go @@ -322,22 +322,6 @@ func TestHasNextCommittedEnts(t *testing.T) { {applied: 3, snap: true, whasNext: false}, } for i, tt := range tests { - storage := NewMemoryStorage() - storage.ApplySnapshot(snap) - raftLog := newLog(storage, raftLogger) - raftLog.append(ents...) - raftLog.maybeCommit(5, 1) - raftLog.appliedTo(tt.applied) - if tt.snap { - newSnap := snap - newSnap.Metadata.Index++ - raftLog.restore(newSnap) - } - - hasNext := raftLog.hasNextCommittedEnts() - if hasNext != tt.whasNext { - t.Errorf("#%d: hasNext = %v, want %v", i, hasNext, tt.whasNext) - } t.Run(fmt.Sprint(i), func(t *testing.T) { storage := NewMemoryStorage() require.NoError(t, storage.ApplySnapshot(snap)) @@ -346,7 +330,12 @@ func TestHasNextCommittedEnts(t *testing.T) { raftLog.append(ents...) raftLog.maybeCommit(5, 1) raftLog.appliedTo(tt.applied) - require.Equal(t, tt.hasNext, raftLog.hasNextCommittedEnts()) + if tt.snap { + newSnap := snap + newSnap.Metadata.Index++ + raftLog.restore(newSnap) + } + require.Equal(t, tt.whasNext, raftLog.hasNextCommittedEnts()) }) } } @@ -373,17 +362,6 @@ func TestNextCommittedEnts(t *testing.T) { {applied: 3, snap: true, wents: nil}, } for i, tt := range tests { - storage := NewMemoryStorage() - storage.ApplySnapshot(snap) - raftLog := newLog(storage, raftLogger) - raftLog.append(ents...) - raftLog.maybeCommit(5, 1) - raftLog.appliedTo(tt.applied) - if tt.snap { - newSnap := snap - newSnap.Metadata.Index++ - raftLog.restore(newSnap) - } t.Run(fmt.Sprint(i), func(t *testing.T) { storage := NewMemoryStorage() require.NoError(t, storage.ApplySnapshot(snap)) @@ -392,6 +370,11 @@ func TestNextCommittedEnts(t *testing.T) { raftLog.append(ents...) raftLog.maybeCommit(5, 1) raftLog.appliedTo(tt.applied) + if tt.snap { + newSnap := snap + newSnap.Metadata.Index++ + raftLog.restore(newSnap) + } require.Equal(t, tt.wents, raftLog.nextCommittedEnts()) })