Ensure subsequent updates to delta don't mutate previously retrieved deltas
(t *testing.T)
| 1308 | |
| 1309 | // Ensure subsequent updates to delta don't mutate previously retrieved deltas |
| 1310 | func TestConcurrentLoad(t *testing.T) { |
| 1311 | cacheHitCounter, cacheMissCounter, getDocumentCounter, getRevisionCounter, cacheNumItems, memoryBytesCounted := base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{}, base.SgwIntStat{} |
| 1312 | backingStoreMap := CreateTestSingleBackingStoreMap(&testBackingStore{nil, &getDocumentCounter, &getRevisionCounter}, testCollectionID) |
| 1313 | cacheOptions := &RevisionCacheOptions{ |
| 1314 | MaxItemCount: 10, |
| 1315 | MaxBytes: 0, |
| 1316 | } |
| 1317 | cache := NewLRURevisionCache(cacheOptions, backingStoreMap, &cacheHitCounter, &cacheMissCounter, &cacheNumItems, &memoryBytesCounted) |
| 1318 | |
| 1319 | cache.Put(base.TestCtx(t), DocumentRevision{BodyBytes: []byte(`{"test":"1234"}`), DocID: "doc1", RevID: "1-abc", CV: &Version{Value: 1234, SourceID: "test"}, History: Revisions{"start": 1}}, testCollectionID) |
| 1320 | |
| 1321 | // Trigger load into cache |
| 1322 | var wg sync.WaitGroup |
| 1323 | wg.Add(20) |
| 1324 | for i := 0; i < 20; i++ { |
| 1325 | go func() { |
| 1326 | _, err := cache.GetWithRev(base.TestCtx(t), "doc1", "1-abc", testCollectionID, false) |
| 1327 | assert.NoError(t, err) |
| 1328 | wg.Done() |
| 1329 | }() |
| 1330 | } |
| 1331 | |
| 1332 | wg.Wait() |
| 1333 | |
| 1334 | } |
| 1335 | |
| 1336 | func TestRevisionCacheRemove(t *testing.T) { |
| 1337 | db, ctx := setupTestDB(t) |
nothing calls this directly
no test coverage detected