TestSkippedSequenceCompact: - Creates change cache with minimal pending seq wait time to push sequences to skipped quick but with small max wait on skipped sequences - Push a sequence higher than expected to cache - Assert that the skipped slice eventually ends up with 0 length and the number of aba
(t *testing.T)
| 2168 | // - Push a sequence higher than expected to cache |
| 2169 | // - Assert that the skipped slice eventually ends up with 0 length and the number of abandoned sequences are as expected |
| 2170 | func TestSkippedSequenceCompact(t *testing.T) { |
| 2171 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll) |
| 2172 | |
| 2173 | ctx := base.TestCtx(t) |
| 2174 | bucket := base.GetTestBucket(t) |
| 2175 | dbContext, err := NewDatabaseContext(ctx, "db", bucket, false, DatabaseContextOptions{ |
| 2176 | Scopes: GetScopesOptions(t, bucket, 1), |
| 2177 | }) |
| 2178 | require.NoError(t, err) |
| 2179 | defer dbContext.Close(ctx) |
| 2180 | |
| 2181 | ctx = dbContext.AddDatabaseLogContext(ctx) |
| 2182 | err = dbContext.StartOnlineProcesses(ctx) |
| 2183 | require.NoError(t, err) |
| 2184 | |
| 2185 | testChangeCache := &changeCache{} |
| 2186 | if err := testChangeCache.Init(ctx, dbContext, dbContext.channelCache, nil, &CacheOptions{ |
| 2187 | CachePendingSeqMaxWait: 5 * time.Millisecond, |
| 2188 | CacheSkippedSeqMaxWait: 2 * time.Second, |
| 2189 | }, dbContext.MetadataKeys); err != nil { |
| 2190 | log.Printf("Init failed for testChangeCache: %v", err) |
| 2191 | t.Fail() |
| 2192 | } |
| 2193 | |
| 2194 | if err := testChangeCache.Start(0); err != nil { |
| 2195 | log.Printf("Start error for testChangeCache: %v", err) |
| 2196 | t.Fail() |
| 2197 | } |
| 2198 | defer testChangeCache.Stop(ctx) |
| 2199 | require.NoError(t, err) |
| 2200 | |
| 2201 | // add cache entry that is higher than expected |
| 2202 | highEntry := &LogEntry{ |
| 2203 | Sequence: 20, |
| 2204 | DocID: fmt.Sprintf("doc_%d", 50), |
| 2205 | RevID: "1-abcdefabcdefabcdef", |
| 2206 | TimeReceived: channels.NewFeedTimestampFromNow(), |
| 2207 | } |
| 2208 | _ = testChangeCache.processEntry(ctx, highEntry) |
| 2209 | |
| 2210 | // assert this pushes an entry on the skipped sequence slice |
| 2211 | require.EventuallyWithT(t, func(c *assert.CollectT) { |
| 2212 | assert.Equal(c, 1, testChangeCache.skippedSeqs.list.GetLength()) |
| 2213 | }, time.Second*10, time.Millisecond*100) |
| 2214 | |
| 2215 | // assert that compaction empties the skipped slice and we have correct value for abandoned sequences |
| 2216 | require.EventuallyWithT(t, func(c *assert.CollectT) { |
| 2217 | testChangeCache.updateStats(ctx) |
| 2218 | assert.Equal(c, int64(0), dbContext.DbStats.CacheStats.SkippedSequenceSkiplistNodes.Value()) |
| 2219 | assert.Equal(c, int64(19), dbContext.DbStats.CacheStats.AbandonedSeqs.Value()) |
| 2220 | assert.Equal(c, int64(0), dbContext.DbStats.CacheStats.NumCurrentSeqsSkipped.Value()) |
| 2221 | }, time.Second*10, time.Millisecond*100) |
| 2222 | } |
| 2223 | |
| 2224 | // TestReleasedSequenceRangeHandlingEverythingSkipped: |
| 2225 | // - Test release of an unused sequence range when all sequences in the range are skipped sequences |
nothing calls this directly
no test coverage detected