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

Function TestAddPendingLogs

db/change_cache_test.go:2928–3106  ·  view source on GitHub ↗

TestAddPendingLogs: - Test age-based eviction of sequences and ranges from pending logs. - Adds to pending logs directly via heap.Push with backdated TimeReceived, triggers eviction with call to _addPendingLogs - tests duplicate handling when popping pending entries - reproduces CBG-4215

(t *testing.T)

Source from the content-addressed store, hash-verified

2926// - tests duplicate handling when popping pending entries
2927// - reproduces CBG-4215
2928func TestAddPendingLogs(t *testing.T) {
2929 base.SetUpTestLogging(t, base.LevelDebug, base.KeyCache, base.KeyChanges)
2930
2931 ctx := base.TestCtx(t)
2932 bucket := base.GetTestBucket(t)
2933 dbContext, err := NewDatabaseContext(ctx, "db", bucket, false, DatabaseContextOptions{
2934 Scopes: GetScopesOptions(t, bucket, 1),
2935 })
2936 require.NoError(t, err)
2937 defer dbContext.Close(ctx)
2938
2939 ctx = dbContext.AddDatabaseLogContext(ctx)
2940 err = dbContext.StartOnlineProcesses(ctx)
2941 require.NoError(t, err)
2942
2943 testCases := []struct {
2944 incoming []sequenceRange // test simulates adding these to pending in the order found in the slice
2945 channelName string // non-range values (endSeq=0) will be assigned to this channel for verification of proper caching
2946 expectedCached []uint64 // expected cached sequences
2947 expectedSkipped []sequenceRange // expected skipped sequence ranges
2948 expectedNextSequence uint64 // expected cache.nextSequence
2949 }{
2950 {
2951 // single range
2952 incoming: []sequenceRange{{2, 4}},
2953 expectedNextSequence: 5,
2954 expectedSkipped: []sequenceRange{{1, 1}},
2955 },
2956 {
2957 // multiple non-overlapping ranges arriving out of sequence order
2958 incoming: []sequenceRange{{2, 4}, {9, 10}, {6, 8}, {14, 20}, {11, 13}, {5, 5}},
2959 expectedNextSequence: 21,
2960 expectedSkipped: []sequenceRange{{1, 1}},
2961 },
2962 {
2963 // non overlapping ranges, arrive in sequence order
2964 incoming: []sequenceRange{{2, 4}, {5, 8}},
2965 expectedNextSequence: 9,
2966 expectedSkipped: []sequenceRange{{1, 1}},
2967 },
2968 {
2969 // non overlapping ranges, arrive out of sequence order
2970 incoming: []sequenceRange{{5, 8}, {2, 4}},
2971 expectedNextSequence: 9,
2972 expectedSkipped: []sequenceRange{{1, 1}},
2973 },
2974 {
2975 // range overlaps single, range arrives first
2976 incoming: []sequenceRange{{2, 4}, {3, 0}},
2977 channelName: "A",
2978 expectedNextSequence: 4,
2979 expectedCached: []uint64{3},
2980 expectedSkipped: []sequenceRange{{1, 1}},
2981 },
2982 {
2983 // single arrives then range overlaps single both sides
2984 incoming: []sequenceRange{{3, 3}, {2, 4}},
2985 expectedNextSequence: 4,

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
getChannelCacheMethod · 0.95
_pushRangeToPendingMethod · 0.95
_addPendingLogsMethod · 0.95
SetUpTestLoggingFunction · 0.92
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92

Tested by

no test coverage detected