Skip to content

Remove TestLowSequenceHandlingNoDuplicates #7318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 0 additions & 72 deletions db/change_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,78 +988,6 @@ func TestChannelQueryCancellation(t *testing.T) {
assert.Equal(t, initialQueryCount+1, finalQueryCount)
}

func TestLowSequenceHandlingNoDuplicates(t *testing.T) {
base.SetUpTestLogging(t, base.LevelDebug, base.KeyChanges, base.KeyCache)

db, ctx := setupTestDBWithCacheOptions(t, shortWaitCache())
defer db.Close(ctx)

// Create a user with access to channel ABC
authenticator := db.Authenticator(ctx)
assert.True(t, authenticator != nil, "db.Authenticator(db.Ctx) returned nil")
user, err := authenticator.NewUser("naomi", "letmein", channels.BaseSetOf(t, "ABC", "PBS", "NBC", "TBS"))
assert.NoError(t, err, fmt.Sprintf("Error creating new user: %v", err))
require.NoError(t, authenticator.Save(user))

collection := GetSingleDatabaseCollection(t, db.DatabaseContext)
// Simulate seq 3 and 4 being delayed - write 1,2,5,6
WriteDirect(t, collection, []string{"ABC", "NBC"}, 1)
WriteDirect(t, collection, []string{"ABC"}, 2)
WriteDirect(t, collection, []string{"ABC", "PBS"}, 5)
WriteDirect(t, collection, []string{"ABC", "PBS"}, 6)

require.NoError(t, db.changeCache.waitForSequence(ctx, 6, base.DefaultWaitForSequence))
db.user, err = authenticator.GetUser("naomi")
require.NoError(t, err)

// Start changes feed

dbCollection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
var options ChangesOptions
options.Since = SequenceID{Seq: 0}
ctx, changesCtxCancel := context.WithCancel(ctx)
options.ChangesCtx = ctx
defer changesCtxCancel()
options.Continuous = true
options.Wait = true
feed, err := dbCollection.MultiChangesFeed(ctx, base.SetOf("*"), options)
assert.True(t, err == nil)

// Array to read changes from feed to support assertions
var changes = make([]*ChangeEntry, 0, 50)

err = appendFromFeed(&changes, feed, 4, base.DefaultWaitForSequence)

// Validate the initial sequences arrive as expected
assert.True(t, err == nil)
assert.Len(t, changes, 4)
assert.Equal(t, &ChangeEntry{
Seq: SequenceID{Seq: 1, TriggeredBy: 0, LowSeq: 2},
ID: "doc-1",
collectionID: dbCollection.GetCollectionID(),
Changes: []ChangeRev{{"rev": "1-a"}}}, changes[0])

// Test backfill clear - sequence numbers go back to standard handling
WriteDirect(t, collection, []string{"ABC", "NBC", "PBS", "TBS"}, 3)
WriteDirect(t, collection, []string{"ABC", "PBS"}, 4)

require.NoError(t, db.changeCache.waitForSequenceNotSkipped(ctx, 4, base.DefaultWaitForSequence))

err = appendFromFeed(&changes, feed, 2, base.DefaultWaitForSequence)
assert.True(t, err == nil)
assert.Len(t, changes, 6)
assert.True(t, verifyChangesSequencesIgnoreOrder(changes, []uint64{1, 2, 5, 6, 3, 4}))

WriteDirect(t, collection, []string{"ABC"}, 7)
WriteDirect(t, collection, []string{"ABC", "NBC"}, 8)
WriteDirect(t, collection, []string{"ABC", "PBS"}, 9)
require.NoError(t, db.changeCache.waitForSequence(ctx, 9, base.DefaultWaitForSequence))
newChanges, err := verifySequencesInFeed(feed, []uint64{7, 8, 9})
require.NoError(t, err)

assert.True(t, verifyChangesSequencesIgnoreOrder(append(changes, newChanges...), []uint64{1, 2, 5, 6, 3, 4, 7, 8, 9}))
}

// Test race condition causing skipped sequences in changes feed. Channel feeds are processed sequentially
// in the main changes.go iteration loop, without a lock on the underlying channel caches. The following
// sequence is possible while running a changes feed for channels "A", "B":
Expand Down
Loading