Test backfill of late arriving sequences to a continuous changes feed
(t *testing.T)
| 576 | |
| 577 | // Test backfill of late arriving sequences to a continuous changes feed |
| 578 | func TestContinuousChangesBackfill(t *testing.T) { |
| 579 | |
| 580 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyCache, base.KeyChanges, base.KeyDCP) |
| 581 | |
| 582 | db, ctx := setupTestDBWithCacheOptions(t, shortWaitCache()) |
| 583 | defer db.Close(ctx) |
| 584 | |
| 585 | // Create a user with access to channel ABC |
| 586 | authenticator := db.Authenticator(ctx) |
| 587 | user, err := authenticator.NewUser("naomi", "letmein", channels.BaseSetOf(t, "ABC", "PBS", "NBC", "CBS")) |
| 588 | require.NoError(t, err) |
| 589 | require.NoError(t, authenticator.Save(user)) |
| 590 | |
| 591 | collection := GetSingleDatabaseCollection(t, db.DatabaseContext) |
| 592 | |
| 593 | // Simulate seq 3 and 4 being delayed - write 1,2,5,6 |
| 594 | WriteDirect(t, collection, []string{"ABC", "NBC"}, 1) |
| 595 | WriteDirect(t, collection, []string{"ABC"}, 2) |
| 596 | WriteDirect(t, collection, []string{"PBS"}, 5) |
| 597 | WriteDirect(t, collection, []string{"CBS"}, 6) |
| 598 | |
| 599 | db.user, err = authenticator.GetUser("naomi") |
| 600 | require.NoError(t, err) |
| 601 | |
| 602 | // Start changes feed |
| 603 | var options ChangesOptions |
| 604 | options.Since = SequenceID{Seq: 0} |
| 605 | ctx, changesCtxCancel := context.WithCancel(ctx) |
| 606 | options.ChangesCtx = ctx |
| 607 | options.Continuous = true |
| 608 | options.Wait = true |
| 609 | defer changesCtxCancel() |
| 610 | |
| 611 | dbCollection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 612 | feed, err := dbCollection.MultiChangesFeed(ctx, base.SetOf("*"), options) |
| 613 | assert.True(t, err == nil) |
| 614 | |
| 615 | time.Sleep(50 * time.Millisecond) |
| 616 | |
| 617 | collection = dbCollection.DatabaseCollection |
| 618 | // Write some more docs |
| 619 | WriteDirect(t, collection, []string{"CBS"}, 3) |
| 620 | WriteDirect(t, collection, []string{"PBS"}, 12) |
| 621 | require.NoError(t, dbCollection.changeCache().waitForSequence(ctx, 12, base.DefaultWaitForSequence)) |
| 622 | |
| 623 | // Test multiple backfill in single changes loop iteration |
| 624 | WriteDirect(t, collection, []string{"ABC", "NBC", "PBS", "CBS"}, 4) |
| 625 | WriteDirect(t, collection, []string{"ABC", "NBC", "PBS", "CBS"}, 7) |
| 626 | WriteDirect(t, collection, []string{"ABC", "PBS"}, 8) |
| 627 | WriteDirect(t, collection, []string{"ABC", "PBS"}, 13) |
| 628 | require.NoError(t, dbCollection.changeCache().waitForSequence(ctx, 13, base.DefaultWaitForSequence)) |
| 629 | time.Sleep(50 * time.Millisecond) |
| 630 | |
| 631 | // We can't guarantee how compound sequences will be generated in a multi-core test - will |
| 632 | // depend on timing of arrival in late sequence logs. e.g. could come through as any one of |
| 633 | // the following (where all are valid), depending on timing: |
| 634 | // ..."4","7","8","8::13" |
| 635 | // ..."4", "6::7", "6::8", "6::13" |
nothing calls this directly
no test coverage detected