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

Function TestConcurrentLoad

db/revision_cache_test.go:1310–1334  ·  view source on GitHub ↗

Ensure subsequent updates to delta don't mutate previously retrieved deltas

(t *testing.T)

Source from the content-addressed store, hash-verified

1308
1309// Ensure subsequent updates to delta don't mutate previously retrieved deltas
1310func 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
1336func TestRevisionCacheRemove(t *testing.T) {
1337 db, ctx := setupTestDB(t)

Callers

nothing calls this directly

Calls 8

PutMethod · 0.95
GetWithRevMethod · 0.95
TestCtxFunction · 0.92
NewLRURevisionCacheFunction · 0.85
DoneMethod · 0.80
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected