Skip to content

Commit

Permalink
fix(327): assert the lastPushed as -1 or 0 (#421)
Browse files Browse the repository at this point in the history
Fixed: #327

The assert.Equal may run before `streamEntries` or after
`streamEntries`, so the LastPushed maybe -1 or 0.

Signed-off-by: Soren Yang <lsytj0413@gmail.com>
  • Loading branch information
lsytj0413 authored Dec 29, 2023
1 parent 53c3f4a commit 5df5466
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/follower_cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ func TestFollowerCursor(t *testing.T) {
fc, err := NewFollowerCursor("f1", term, common.DefaultNamespace, shard, stream, ackTracker, w, db, wal.InvalidOffset)
assert.NoError(t, err)

time.Sleep(10 * time.Millisecond)

assert.Equal(t, shard, fc.ShardId())
assert.Equal(t, wal.InvalidOffset, fc.LastPushed())
// NOTE: lastPushed will be -1 or 0, because when FollowerCursor is initialized,
// it will start to `streamEntries` and maybe make it advanced to 0.
assert.True(t, func() bool {
lastPushed := fc.LastPushed()
return lastPushed == wal.InvalidOffset || lastPushed == 0
}())
assert.Equal(t, wal.InvalidOffset, fc.AckOffset())

assert.Eventually(t, func() bool {
Expand Down

0 comments on commit 5df5466

Please sign in to comment.