Test Cases - simple compact - validate compaction stops at LWM - validate compaction continues - multiple calls to start - compact with concurrent additions to cache - getChanges when cache full
(t *testing.T)
| 122 | // - getChanges when cache full |
| 123 | |
| 124 | func TestChannelCacheSimpleCompact(t *testing.T) { |
| 125 | |
| 126 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyCache) |
| 127 | |
| 128 | // Define cache with max channels 20, hwm will be 16, low water mark will be 12 |
| 129 | options := DefaultCacheOptions().ChannelCacheOptions |
| 130 | options.MaxNumChannels = 20 |
| 131 | |
| 132 | stats, err := base.NewSyncGatewayStats() |
| 133 | require.NoError(t, err) |
| 134 | dbstats, err := stats.NewDBStats("", false, false, false, nil, nil) |
| 135 | require.NoError(t, err) |
| 136 | testStats := dbstats.Cache() |
| 137 | activeChannelStat := &base.SgwIntStat{} |
| 138 | activeChannels := channels.NewActiveChannels(activeChannelStat) |
| 139 | ctx := base.TestCtx(t) |
| 140 | cache, err := newChannelCache(base.TestCtx(t), "testDb", options, testQueryHandlerFactory, activeChannels, testStats) |
| 141 | require.NoError(t, err, "Background task error whilst creating channel cache") |
| 142 | defer cache.Stop(ctx) |
| 143 | |
| 144 | require.NoError(t, err) |
| 145 | |
| 146 | // Add 16 channels to the cache. Shouldn't trigger compaction (hwm is not exceeded) |
| 147 | for i := 1; i <= 16; i++ { |
| 148 | channelName := fmt.Sprintf("chan_%d", i) |
| 149 | cache.addChannelCache(ctx, channels.NewID(channelName, base.DefaultCollectionID)) |
| 150 | } |
| 151 | // Validate cache size |
| 152 | assert.Equal(t, 16, cache.channelCaches.Length()) |
| 153 | |
| 154 | // Add another channel to cache |
| 155 | cache.addChannelCache(ctx, channels.NewID("chan_17", base.DefaultCollectionID)) |
| 156 | |
| 157 | assert.True(t, waitForCompaction(cache), "Compaction didn't complete in expected time") |
| 158 | |
| 159 | // Validate cache size |
| 160 | assert.Equal(t, 12, cache.channelCaches.Length()) |
| 161 | |
| 162 | } |
| 163 | |
| 164 | func TestChannelCacheCompactInactiveChannels(t *testing.T) { |
| 165 |
nothing calls this directly
no test coverage detected