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

Function TestChannelCacheHighLoadCacheHit

db/channel_cache_test.go:321–391  ·  view source on GitHub ↗

TestChannelCacheHighLoadCache validates behaviour under high query load when the total number of channels is lower than or equal to the CompactHighWatermark

(t *testing.T)

Source from the content-addressed store, hash-verified

319// TestChannelCacheHighLoadCache validates behaviour under high query load when the total number of channels is lower than
320// or equal to the CompactHighWatermark
321func TestChannelCacheHighLoadCacheHit(t *testing.T) {
322
323 base.SetUpTestLogging(t, base.LevelTrace, base.KeyCache)
324
325 // Define cache with max channels 20, watermarks 50/90
326 options := DefaultCacheOptions().ChannelCacheOptions
327 options.MaxNumChannels = 100
328 options.CompactHighWatermarkPercent = 90
329 options.CompactLowWatermarkPercent = 70
330
331 stats, err := base.NewSyncGatewayStats()
332 require.NoError(t, err)
333 dbstats, err := stats.NewDBStats("", false, false, false, nil, nil)
334 require.NoError(t, err)
335 testStats := dbstats.Cache()
336 queryHandler := &testQueryHandler{}
337 activeChannelStat := &base.SgwIntStat{}
338 activeChannels := channels.NewActiveChannels(activeChannelStat)
339 ctx := base.TestCtx(t)
340 cache, err := newChannelCache(ctx, "testDb", options, queryHandler.asFactory, activeChannels, testStats)
341 require.NoError(t, err, "Background task error whilst creating channel cache")
342 defer cache.Stop(ctx)
343
344 channelCount := 90
345 // define channel set
346 channelNames := make([]string, 0)
347 for i := 1; i <= channelCount; i++ {
348 channelName := fmt.Sprintf("chan_%d", i)
349 channelNames = append(channelNames, channelName)
350 }
351
352 // Seed the query handler with a single doc that's in all the channels
353 queryEntry := testLogEntryForChannels(1, channelNames)
354 queryHandler.seedEntries(LogEntries{queryEntry})
355
356 // Send entry to the cache. Don't reuse queryEntry here, as AddToCache strips out the channels property
357 logEntry := testLogEntryForChannels(1, channelNames)
358 cache.AddToCache(ctx, logEntry)
359
360 workerCount := 25
361 getChangesCount := 400
362 // Start [workerCount] goroutines, each issuing [getChangesCount] changes queries against a random channel
363
364 var workerWg sync.WaitGroup
365 for w := 0; w < workerCount; w++ {
366 workerWg.Add(1)
367 go func() {
368 changesSuccessCount := 0
369 for i := 0; i < getChangesCount; i++ {
370 channelNumber := rand.Intn(channelCount) + 1
371 channel := channels.NewID(fmt.Sprintf("chan_%d", channelNumber), base.DefaultCollectionID)
372 options := getChangesOptionsWithCtxOnly(t)
373 changes, err := cache.GetChanges(base.TestCtx(t), channel, options)
374 if len(changes) == 1 {
375 changesSuccessCount++
376 }
377 assert.NoError(t, err, fmt.Sprintf("Error getting changes for channel %s", channel))
378 assert.True(t, len(changes) == 1, "Expected one change per channel")

Callers

nothing calls this directly

Calls 15

seedEntriesMethod · 0.95
SetUpTestLoggingFunction · 0.92
NewSyncGatewayStatsFunction · 0.92
NewActiveChannelsFunction · 0.92
TestCtxFunction · 0.92
NewIDFunction · 0.92
DefaultCacheOptionsFunction · 0.85
newChannelCacheFunction · 0.85
testLogEntryForChannelsFunction · 0.85
NewDBStatsMethod · 0.80
CacheMethod · 0.80

Tested by

no test coverage detected