Test low sequence handling of late arriving sequences to a continuous changes feed
(t *testing.T)
| 677 | |
| 678 | // Test low sequence handling of late arriving sequences to a continuous changes feed |
| 679 | func TestLowSequenceHandling(t *testing.T) { |
| 680 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyCache, base.KeyChanges, base.KeyQuery) |
| 681 | |
| 682 | db, ctx := setupTestDBWithCacheOptions(t, shortWaitCache()) |
| 683 | defer db.Close(ctx) |
| 684 | |
| 685 | // Create a user with access to channel ABC |
| 686 | authenticator := db.Authenticator(ctx) |
| 687 | assert.True(t, authenticator != nil, "db.Authenticator(ctx) returned nil") |
| 688 | user, err := authenticator.NewUser("naomi", "letmein", channels.BaseSetOf(t, "ABC", "PBS", "NBC", "TBS")) |
| 689 | assert.NoError(t, err, fmt.Sprintf("Error creating new user: %v", err)) |
| 690 | require.NoError(t, authenticator.Save(user)) |
| 691 | |
| 692 | collection := GetSingleDatabaseCollection(t, db.DatabaseContext) |
| 693 | // Simulate seq 3 and 4 being delayed - write 1,2,5,6 |
| 694 | WriteDirect(t, collection, []string{"ABC", "NBC"}, 1) |
| 695 | WriteDirect(t, collection, []string{"ABC"}, 2) |
| 696 | WriteDirect(t, collection, []string{"ABC", "PBS"}, 5) |
| 697 | WriteDirect(t, collection, []string{"ABC", "PBS"}, 6) |
| 698 | |
| 699 | dbCollection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 700 | require.NoError(t, dbCollection.changeCache().waitForSequence(ctx, 6, base.DefaultWaitForSequence)) |
| 701 | dbCollection.user, err = authenticator.GetUser("naomi") |
| 702 | require.NoError(t, err) |
| 703 | |
| 704 | // Start changes feed |
| 705 | |
| 706 | var options ChangesOptions |
| 707 | options.Since = SequenceID{Seq: 0} |
| 708 | changesCtx, changesCtxCancel := context.WithCancel(base.TestCtx(t)) |
| 709 | options.ChangesCtx = changesCtx |
| 710 | defer changesCtxCancel() |
| 711 | options.Continuous = true |
| 712 | options.Wait = true |
| 713 | feed, err := dbCollection.MultiChangesFeed(ctx, base.SetOf("*"), options) |
| 714 | assert.True(t, err == nil) |
| 715 | |
| 716 | changes, err := verifySequencesInFeed(feed, []uint64{1, 2, 5, 6}) |
| 717 | assert.True(t, err == nil) |
| 718 | require.Len(t, changes, 4) |
| 719 | |
| 720 | collectionID := collection.GetCollectionID() |
| 721 | |
| 722 | require.Equal(t, &ChangeEntry{ |
| 723 | Seq: SequenceID{Seq: 1, TriggeredBy: 0, LowSeq: 2}, |
| 724 | ID: "doc-1", |
| 725 | Changes: []ChangeByVersionType{{"rev": "1-a"}}, |
| 726 | collectionID: collectionID}, changes[0]) |
| 727 | |
| 728 | // Test backfill clear - sequence numbers go back to standard handling |
| 729 | WriteDirect(t, collection, []string{"ABC", "NBC", "PBS", "TBS"}, 3) |
| 730 | WriteDirect(t, collection, []string{"ABC", "PBS"}, 4) |
| 731 | |
| 732 | _, err = verifySequencesInFeed(feed, []uint64{3, 4}) |
| 733 | assert.True(t, err == nil) |
| 734 | |
| 735 | WriteDirect(t, collection, []string{"ABC"}, 7) |
| 736 | WriteDirect(t, collection, []string{"ABC", "NBC"}, 8) |
nothing calls this directly
no test coverage detected