MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestProcessSkippedEntry

Function TestProcessSkippedEntry

db/change_cache_test.go:2018–2087  ·  view source on GitHub ↗

TestProcessSkippedEntry: - Creates change cache with minimal pending seq wait time to push sequences to skipped quick - Push a sequence higher than expected to cache - Have NewTestProcessEntryFeed push sequences to the cache and assert that the current skipped sequence count decrements each time - I

(t *testing.T)

Source from the content-addressed store, hash-verified

2016// - Assert that the length of slice stat is equal to the length of the skipped sequence slice + assert that number of
2017// sequences skipped overall stat is correct
2018func TestProcessSkippedEntry(t *testing.T) {
2019 base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
2020
2021 ctx := base.TestCtx(t)
2022 bucket := base.GetTestBucket(t)
2023 dbContext, err := NewDatabaseContext(ctx, "db", bucket, false, DatabaseContextOptions{
2024 Scopes: GetScopesOptions(t, bucket, 1),
2025 })
2026 require.NoError(t, err)
2027 defer dbContext.Close(ctx)
2028
2029 ctx = dbContext.AddDatabaseLogContext(ctx)
2030 err = dbContext.StartOnlineProcesses(ctx)
2031 require.NoError(t, err)
2032
2033 testChangeCache := &changeCache{}
2034 if err := testChangeCache.Init(ctx, dbContext, dbContext.channelCache, nil, &CacheOptions{
2035 CachePendingSeqMaxWait: 5 * time.Millisecond,
2036 CacheSkippedSeqMaxWait: 2 * time.Minute,
2037 }, dbContext.MetadataKeys); err != nil {
2038 log.Printf("Init failed for testChangeCache: %v", err)
2039 t.Fail()
2040 }
2041
2042 if err := testChangeCache.Start(0); err != nil {
2043 log.Printf("Start error for testChangeCache: %v", err)
2044 t.Fail()
2045 }
2046 defer testChangeCache.Stop(ctx)
2047 require.NoError(t, err)
2048
2049 feed := NewTestProcessEntryFeed(1, 5)
2050
2051 // add cache entry that is higher than expected
2052 highEntry := &LogEntry{
2053 Sequence: 20,
2054 DocID: fmt.Sprintf("doc_%d", 50),
2055 RevID: "1-abcdefabcdefabcdef",
2056 TimeReceived: channels.NewFeedTimestampFromNow(),
2057 }
2058 _ = testChangeCache.processEntry(ctx, highEntry)
2059
2060 // update cache stats for assertions
2061 testChangeCache.updateStats(ctx)
2062
2063 // assert this pushes an entry on the skipped sequence slice
2064 require.EventuallyWithT(t, func(c *assert.CollectT) {
2065 assert.Equal(c, 1, testChangeCache.skippedSeqs.list.GetLength())
2066 }, time.Second*10, time.Millisecond*100)
2067
2068 // process some sequences over cache
2069 currNumSkippedSeqs := dbContext.DbStats.CacheStats.NumCurrentSeqsSkipped.Value()
2070 for j := 0; j < 10; j++ {
2071 en := feed.Next()
2072 _ = testChangeCache.processEntry(ctx, en)
2073 testChangeCache.updateStats(ctx)
2074 assert.Equal(t, currNumSkippedSeqs-1, dbContext.DbStats.CacheStats.NumCurrentSeqsSkipped.Value())
2075 currNumSkippedSeqs = dbContext.DbStats.CacheStats.NumCurrentSeqsSkipped.Value()

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
AddDatabaseLogContextMethod · 0.95
StartOnlineProcessesMethod · 0.95
InitMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
processEntryMethod · 0.95
updateStatsMethod · 0.95
SetUpTestLoggingFunction · 0.92
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
NewFeedTimestampFromNowFunction · 0.92

Tested by

no test coverage detected