TestCurrentVersionPopulationOnChannelCache: - Make channel active on cache - Add a doc that is assigned this channel - Get the sync data of that doc to assert against the HLV defined on it - Wait for the channel cache to be populated with this doc write - Assert the CV in the entry fetched from chan
(t *testing.T)
| 578 | // - Wait for the channel cache to be populated with this doc write |
| 579 | // - Assert the CV in the entry fetched from channel cache matches the sync data CV and the bucket UUID on the database context |
| 580 | func TestCurrentVersionPopulationOnChannelCache(t *testing.T) { |
| 581 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD, base.KeyImport, base.KeyDCP, base.KeyCache, base.KeyHTTP) |
| 582 | db, ctx := setupTestDB(t) |
| 583 | defer db.Close(ctx) |
| 584 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 585 | collectionID := collection.GetCollectionID() |
| 586 | bucketUUID := db.EncodedSourceID |
| 587 | collection.ChannelMapper = channels.NewChannelMapper(ctx, channels.DocChannelsSyncFunction, db.Options.JavascriptTimeout) |
| 588 | |
| 589 | // Make channel active |
| 590 | _, err := db.channelCache.GetChanges(ctx, channels.NewID("ABC", collectionID), getChangesOptionsWithZeroSeq(t)) |
| 591 | require.NoError(t, err) |
| 592 | |
| 593 | // Put a doc that gets assigned a CV to populate the channel cache with |
| 594 | _, _, err = collection.Put(ctx, "doc1", Body{"channels": []string{"ABC"}}) |
| 595 | require.NoError(t, err) |
| 596 | err = collection.WaitForPendingChanges(base.TestCtx(t)) |
| 597 | require.NoError(t, err) |
| 598 | |
| 599 | doc, err := collection.GetDocument(ctx, "doc1", DocUnmarshalSync) |
| 600 | require.NoError(t, err) |
| 601 | |
| 602 | // get entry of above doc from channel cache |
| 603 | entries, err := db.channelCache.GetChanges(ctx, channels.NewID("ABC", collectionID), getChangesOptionsWithZeroSeq(t)) |
| 604 | require.NoError(t, err) |
| 605 | require.NotNil(t, entries) |
| 606 | |
| 607 | // assert that the source and version has been populated with the channel cache entry for the doc |
| 608 | assert.Equal(t, "doc1", entries[0].DocID) |
| 609 | assert.Equal(t, base.HexCasToUint64(doc.SyncData.Cas), entries[0].Version) |
| 610 | assert.Equal(t, bucketUUID, entries[0].SourceID) |
| 611 | assert.Equal(t, doc.HLV.SourceID, entries[0].SourceID) |
| 612 | assert.Equal(t, doc.HLV.Version, entries[0].Version) |
| 613 | } |
nothing calls this directly
no test coverage detected