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

Function TestPutRevHighRevCacheChurn

db/revision_cache_test.go:2185–2227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2183}
2184
2185func TestPutRevHighRevCacheChurn(t *testing.T) {
2186
2187 dbcOptions := DatabaseContextOptions{
2188 RevisionCacheOptions: &RevisionCacheOptions{
2189 MaxItemCount: 2,
2190 ShardCount: 1,
2191 },
2192 }
2193 var wg sync.WaitGroup
2194 db, ctx := SetupTestDBWithOptions(t, dbcOptions)
2195 defer db.Close(ctx)
2196 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
2197 docID := "doc1"
2198 wg.Add(1)
2199
2200 testCtx, testCtxCancel := context.WithCancel(base.TestCtx(t))
2201 defer testCtxCancel()
2202
2203 for i := 0; i < 2; i++ {
2204 docID := fmt.Sprintf("extraDoc%d", i)
2205 revID, _, err := collection.Put(ctx, docID, Body{"fake": "body"})
2206 require.NoError(t, err)
2207 go func() {
2208 for {
2209 select {
2210 case <-testCtx.Done():
2211 return
2212 default:
2213 _, err = db.revisionCache.GetWithRev(ctx, docID, revID, collection.GetCollectionID(), RevCacheOmitDelta) //nolint:errcheck
2214 }
2215 }
2216 }()
2217 }
2218
2219 go func() {
2220 for i := 0; i < 100; i++ {
2221 docRev := DocumentRevision{DocID: docID, RevID: fmt.Sprintf("1-%d", i), CV: &Version{SourceID: "someSrc", Value: uint64(i)}, BodyBytes: []byte(fmt.Sprintf(`{"ver": "%d"}`, i)), History: Revisions{"start": 1}}
2222 db.revisionCache.Put(ctx, docRev, collection.GetCollectionID())
2223 }
2224 wg.Done()
2225 }()
2226 wg.Wait()
2227}
2228
2229func TestRevCacheOnDemandImportNoCache(t *testing.T) {
2230 base.SkipImportTestsIfNotEnabled(t)

Callers

nothing calls this directly

Calls 10

TestCtxFunction · 0.92
SetupTestDBWithOptionsFunction · 0.85
DoneMethod · 0.80
CloseMethod · 0.65
PutMethod · 0.65
GetWithRevMethod · 0.65
AddMethod · 0.45
GetCollectionIDMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected