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

Function TestTombstoneCompactionStopWithManager

db/database_test.go:3747–3806  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3745}
3746
3747func TestTombstoneCompactionStopWithManager(t *testing.T) {
3748
3749 if !base.TestUseXattrs() {
3750 t.Skip("Compaction requires xattrs")
3751 }
3752
3753 bucket := base.GetTestBucket(t).LeakyBucketClone(base.LeakyBucketConfig{})
3754 db, ctx := SetupTestDBForBucketWithOptions(t, bucket, DatabaseContextOptions{
3755 TestPurgeIntervalOverride: base.Ptr(time.Duration(0)),
3756 })
3757 defer db.Close(ctx)
3758 collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
3759
3760 for i := 0; i < 300; i++ {
3761 docID := fmt.Sprintf("doc%d", i)
3762 rev, _, err := collection.Put(ctx, docID, Body{})
3763 assert.NoError(t, err)
3764 _, _, err = collection.DeleteDoc(ctx, docID, DocVersion{RevTreeID: rev})
3765 assert.NoError(t, err)
3766 }
3767
3768 require.NoError(t, collection.WaitForPendingChanges(ctx))
3769
3770 leakyDataStore, ok := base.AsLeakyDataStore(collection.dataStore)
3771 require.True(t, ok)
3772
3773 queryCount := 0
3774 callbackFunc := func() {
3775 queryCount++
3776 if queryCount == 2 {
3777 assert.NoError(t, db.TombstoneCompactionManager.Stop())
3778 }
3779 }
3780
3781 // FIXME (bbrks): These callbacks are not firing due to leakyDataStore being set in test and not inside SG
3782 if base.TestsDisableGSI() {
3783 leakyDataStore.SetPostQueryCallback(func(ddoc, viewName string, params map[string]interface{}) {
3784 callbackFunc()
3785 })
3786 } else {
3787 leakyDataStore.SetPostN1QLQueryCallback(func() {
3788 callbackFunc()
3789 })
3790 }
3791
3792 assert.NoError(t, db.TombstoneCompactionManager.Start(ctx, map[string]interface{}{"database": db}))
3793
3794 waitAndAssertConditionWithOptions(t, func() bool {
3795 return db.TombstoneCompactionManager.GetRunState() == BackgroundProcessStateStopped
3796 }, 60, 1000)
3797
3798 var tombstoneCompactionStatus TombstoneManagerResponse
3799 status, err := db.TombstoneCompactionManager.GetStatus(ctx)
3800 assert.NoError(t, err)
3801 err = base.JSONUnmarshal(status, &tombstoneCompactionStatus)
3802 assert.NoError(t, err)
3803
3804 // Ensure only 250 docs have been purged which is one iteration of querying - Means stop did terminate the compaction

Callers

nothing calls this directly

Calls 15

TestUseXattrsFunction · 0.92
GetTestBucketFunction · 0.92
PtrFunction · 0.92
AsLeakyDataStoreFunction · 0.92
TestsDisableGSIFunction · 0.92
JSONUnmarshalFunction · 0.92
LeakyBucketCloneMethod · 0.80
SetPostQueryCallbackMethod · 0.80

Tested by

no test coverage detected