Test size config
(t *testing.T)
| 1157 | |
| 1158 | // Test size config |
| 1159 | func TestChannelCacheSize(t *testing.T) { |
| 1160 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyCache) |
| 1161 | |
| 1162 | options := DefaultCacheOptions() |
| 1163 | options.ChannelCacheOptions.ChannelCacheMinLength = 600 |
| 1164 | options.ChannelCacheOptions.ChannelCacheMaxLength = 600 |
| 1165 | |
| 1166 | log.Printf("Options in test:%+v", options) |
| 1167 | db, ctx := setupTestDBWithCacheOptions(t, options) |
| 1168 | defer db.Close(ctx) |
| 1169 | |
| 1170 | // Create a user with access to channel ABC |
| 1171 | authenticator := db.Authenticator(ctx) |
| 1172 | user, err := authenticator.NewUser("naomi", "letmein", channels.BaseSetOf(t, "ABC")) |
| 1173 | require.NoError(t, err) |
| 1174 | require.NoError(t, authenticator.Save(user)) |
| 1175 | |
| 1176 | collection := GetSingleDatabaseCollection(t, db.DatabaseContext) |
| 1177 | // Write 750 docs to channel ABC |
| 1178 | for i := 1; i <= 750; i++ { |
| 1179 | WriteDirect(t, collection, []string{"ABC"}, uint64(i)) |
| 1180 | } |
| 1181 | |
| 1182 | // Validate that retrieval returns expected sequences |
| 1183 | require.NoError(t, db.changeCache.waitForSequence(ctx, 750, base.DefaultWaitForSequence)) |
| 1184 | collectionWithUser, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 1185 | collectionWithUser.user, err = authenticator.GetUser("naomi") |
| 1186 | require.NoError(t, err) |
| 1187 | changes := getChanges(t, collectionWithUser, base.SetOf("ABC"), getChangesOptionsWithZeroSeq(t)) |
| 1188 | assert.Len(t, changes, 750) |
| 1189 | |
| 1190 | // Validate that cache stores the expected number of values |
| 1191 | collectionID := collection.GetCollectionID() |
| 1192 | |
| 1193 | abcCache, err := db.changeCache.getChannelCache().getSingleChannelCache(ctx, channels.NewID("ABC", collectionID)) |
| 1194 | require.NoError(t, err) |
| 1195 | |
| 1196 | assert.Len(t, abcCache.(*singleChannelCacheImpl).logs, 600) |
| 1197 | } |
| 1198 | |
| 1199 | func shortWaitCache() CacheOptions { |
| 1200 |
nothing calls this directly
no test coverage detected