Skip to content

Commit ac42c0a

Browse files
authored
CBG-5126: disable rev cache test env (#8016)
1 parent 8764066 commit ac42c0a

17 files changed

+144
-12
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,25 @@ jobs:
136136
with:
137137
test-results: test.json
138138

139+
test-disable-rev-cache:
140+
runs-on: ubuntu-latest
141+
env:
142+
GOPRIVATE: github.com/couchbaselabs
143+
SG_TEST_DISABLE_REV_CACHE: true
144+
steps:
145+
- uses: actions/checkout@v5
146+
- uses: actions/setup-go@v5
147+
with:
148+
go-version: 1.25.6
149+
- name: Run Tests
150+
run: go test -tags cb_sg_devmode -shuffle=on -timeout=30m -count=1 -json -v "./..." | tee test.json | jq -s -jr 'sort_by(.Package,.Time) | .[].Output | select (. != null )'
151+
shell: bash
152+
- name: Annotate Failures
153+
if: always()
154+
uses: guyarb/golang-test-annotations@v0.8.0
155+
with:
156+
test-results: test.json
157+
139158
python-format:
140159
runs-on: ubuntu-latest
141160
steps:

base/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const (
4747
TestEnvSyncGatewayUseXattrs = "SG_TEST_USE_XATTRS"
4848
TestEnvSyncGatewayTrue = "True"
4949

50+
// TestEnvDisableRevCache if set to true will disable the revision cache for tests
51+
TestEnvDisableRevCache = "SG_TEST_DISABLE_REV_CACHE"
52+
5053
// Should the tests drop the GSI indexes?
5154
TestEnvSyncGatewayDropIndexes = "SG_TEST_DROP_INDEXES"
5255

base/util_testing.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ func TestsDisableGSI() bool {
284284
return !useGSI
285285
}
286286

287+
// TestDisableRevCache returns true if environment variable SG_TEST_DISABLE_REV_CACHE is set to true
288+
func TestDisableRevCache() bool {
289+
if disableRevCache := os.Getenv(TestEnvDisableRevCache); disableRevCache != "" {
290+
val, _ := strconv.ParseBool(disableRevCache)
291+
return val
292+
}
293+
return false
294+
}
295+
287296
// Check the whether tests are being run with SG_TEST_BACKING_STORE=Couchbase
288297
func TestUseCouchbaseServer() bool {
289298
backingStore := os.Getenv(TestEnvSyncGatewayBackingStore)

db/attachment_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func TestBackupOldRevisionWithAttachments(t *testing.T) {
107107
}
108108

109109
func TestGetBackupRevisionWhenCurrentRevisionHasAttachments(t *testing.T) {
110+
if base.TestDisableRevCache() {
111+
t.Skip("pending fix in CBG-5141")
112+
}
110113
base.SetUpTestLogging(t, base.LevelDebug, base.KeyAll)
111114

112115
db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
@@ -138,7 +141,7 @@ func TestGetBackupRevisionWhenCurrentRevisionHasAttachments(t *testing.T) {
138141
require.NoError(t, err)
139142

140143
// assert version is fetched and attachments is empty
141-
assert.Equal(t, docRev.CV.String(), doc1.HLV.GetCurrentVersionString())
144+
assert.Equal(t, doc1.HLV.GetCurrentVersionString(), docRev.CV.String())
142145
assert.Empty(t, docRev.Attachments)
143146
}
144147

db/database_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,9 @@ func TestDeltaSyncConcurrentClientCachePopulation(t *testing.T) {
11541154
if !base.IsEnterpriseEdition() {
11551155
t.Skip("Delta sync only supported in EE")
11561156
}
1157+
if base.TestDisableRevCache() {
1158+
t.Skip("test requires revision cache to be enabled")
1159+
}
11571160

11581161
tests := []struct {
11591162
name string
@@ -1661,7 +1664,6 @@ func TestGetRemovedAndDeleted(t *testing.T) {
16611664
assert.NoError(t, err, "Put")
16621665

16631666
rev2body := Body{
1664-
"key1": 1234,
16651667
BodyDeleted: true,
16661668
BodyRev: rev1id,
16671669
}
@@ -1683,7 +1685,6 @@ func TestGetRemovedAndDeleted(t *testing.T) {
16831685
rev2digest := rev2id[2:]
16841686
rev1digest := rev1id[2:]
16851687
expectedResult := Body{
1686-
"key1": 1234,
16871688
BodyDeleted: true,
16881689
BodyRevisions: Revisions{
16891690
RevisionsStart: 2,

db/revision_cache_bypass.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (rc *BypassRevisionCache) GetWithRev(ctx context.Context, docID, revID stri
4040

4141
docRev = DocumentRevision{
4242
RevID: revID,
43+
DocID: docID,
4344
RevCacheValueDeltaLock: &sync.Mutex{}, // initialize the mutex for delta updates
4445
}
4546
var hlv *HybridLogicalVector
@@ -62,6 +63,7 @@ func (rc *BypassRevisionCache) GetWithCV(ctx context.Context, docID string, cv *
6263

6364
docRev = DocumentRevision{
6465
CV: cv,
66+
DocID: docID,
6567
RevCacheValueDeltaLock: &sync.Mutex{}, // initialize the mutex for delta updates
6668
}
6769

@@ -95,6 +97,7 @@ func (rc *BypassRevisionCache) GetActive(ctx context.Context, docID string, coll
9597

9698
docRev = DocumentRevision{
9799
RevID: doc.GetRevTreeID(),
100+
DocID: docID,
98101
RevCacheValueDeltaLock: &sync.Mutex{}, // initialize the mutex for delta updates
99102
}
100103

db/revision_cache_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ func TestLRURevisionCacheEvictionMixedRevAndCV(t *testing.T) {
277277
}
278278

279279
func TestLRURevisionCacheEvictionMemoryBased(t *testing.T) {
280+
if base.TestDisableRevCache() {
281+
t.Skip("Revision cache disabled, eviction test needs revision cache enabled")
282+
}
280283
testCases := []struct {
281284
name string
282285
UseCVCache bool
@@ -691,6 +694,9 @@ func TestBypassRevisionCache(t *testing.T) {
691694
// Ensure attachment properties aren't being incorrectly stored in revision cache body when inserted via Put
692695
func TestPutRevisionCacheAttachmentProperty(t *testing.T) {
693696

697+
if base.TestDisableRevCache() {
698+
t.Skip("Revision cache expected to be used for this test")
699+
}
694700
base.SetUpTestLogging(t, base.LevelInfo, base.KeyAll)
695701

696702
db, ctx := setupTestDB(t)
@@ -959,6 +965,9 @@ func TestImmediateRevCacheMemoryBasedEviction(t *testing.T) {
959965
// - Add new doc that will take over the shard memory capacity and assert that that eviction takes place and
960966
// all stats are as expected
961967
func TestShardedMemoryEviction(t *testing.T) {
968+
if base.TestDisableRevCache() {
969+
t.Skip("Test is sharded revision cache specific")
970+
}
962971
dbcOptions := DatabaseContextOptions{
963972
RevisionCacheOptions: &RevisionCacheOptions{
964973
MaxBytes: 160,
@@ -1009,6 +1018,9 @@ func TestShardedMemoryEviction(t *testing.T) {
10091018
// - Test adding a doc to sharded revision cache that will immediately be evicted due to size
10101019
// - Assert that stats look as expected
10111020
func TestShardedMemoryEvictionWhenShardEmpty(t *testing.T) {
1021+
if base.TestDisableRevCache() {
1022+
t.Skip("test is sharded revision cache specific")
1023+
}
10121024
dbcOptions := DatabaseContextOptions{
10131025
RevisionCacheOptions: &RevisionCacheOptions{
10141026
MaxBytes: 100,
@@ -1112,6 +1124,9 @@ func TestImmediateRevCacheItemBasedEviction(t *testing.T) {
11121124
}
11131125

11141126
func TestResetRevCache(t *testing.T) {
1127+
if base.TestDisableRevCache() {
1128+
t.Skip("Revision cache expected to be used for this test")
1129+
}
11151130
dbcOptions := DatabaseContextOptions{
11161131
RevisionCacheOptions: &RevisionCacheOptions{
11171132
MaxBytes: 100,
@@ -1137,6 +1152,9 @@ func TestResetRevCache(t *testing.T) {
11371152
}
11381153

11391154
func TestBasicOperationsOnCacheWithMemoryStat(t *testing.T) {
1155+
if base.TestDisableRevCache() {
1156+
t.Skip("Revision cache expected to be used for this test")
1157+
}
11401158
testCases := []struct {
11411159
name string
11421160
UseCVCache bool
@@ -1333,6 +1351,9 @@ func TestConcurrentLoad(t *testing.T) {
13331351
}
13341352

13351353
func TestRevisionCacheRemove(t *testing.T) {
1354+
if base.TestDisableRevCache() {
1355+
t.Skip("test requires revision cache to be enabled")
1356+
}
13361357
db, ctx := setupTestDB(t)
13371358
defer db.Close(ctx)
13381359
collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db)
@@ -1375,6 +1396,9 @@ func TestRevisionCacheRemove(t *testing.T) {
13751396
// - Assert each doc returned is the correct one (correct rev ID etc)
13761397
// - Assert that each doc is found at the rev cache and no misses are reported
13771398
func TestRevCacheHitMultiCollection(t *testing.T) {
1399+
if base.TestDisableRevCache() {
1400+
t.Skip("test requires revision cache to be enabled")
1401+
}
13781402
base.TestRequiresCollections(t)
13791403

13801404
tb := base.GetTestBucket(t)
@@ -2226,6 +2250,9 @@ func TestPutRevHighRevCacheChurn(t *testing.T) {
22262250
}
22272251

22282252
func TestRevCacheOnDemandImportNoCache(t *testing.T) {
2253+
if base.TestDisableRevCache() {
2254+
t.Skip("test requires rev cache enabled")
2255+
}
22292256
base.SkipImportTestsIfNotEnabled(t)
22302257

22312258
db, ctx := setupTestDB(t)
@@ -2255,6 +2282,9 @@ func TestRevCacheOnDemandImportNoCache(t *testing.T) {
22552282
}
22562283

22572284
func TestFetchBackupWithDeletedFlag(t *testing.T) {
2285+
if base.TestDisableRevCache() {
2286+
t.Skip("pending fix in CBG-5141")
2287+
}
22582288
db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
22592289
// enable delta sync so CV revs are backed up
22602290
DeltaSyncOptions: DeltaSyncOptions{
@@ -2354,6 +2384,9 @@ func TestRemoveFromRevLookup(t *testing.T) {
23542384
}
23552385

23562386
func TestLoadFromBucketLegacyRevsThatAreBackedUpPreUpgrade(t *testing.T) {
2387+
if base.TestDisableRevCache() {
2388+
t.Skip("test requires rev cache enabled")
2389+
}
23572390
db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
23582391
OldRevExpirySeconds: base.DefaultOldRevExpirySeconds,
23592392
RevisionCacheOptions: &RevisionCacheOptions{
@@ -2561,6 +2594,9 @@ func TestUpdateDeltaRevCacheMemoryStatPanicMultipleEntries(t *testing.T) {
25612594
}
25622595

25632596
func TestEvictionOfRevIDKeysWhenNoItemInCVMap(t *testing.T) {
2597+
if base.TestDisableRevCache() {
2598+
t.Skip("test requires rev cache enabled for eviction to run")
2599+
}
25642600
db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
25652601
OldRevExpirySeconds: base.DefaultOldRevExpirySeconds,
25662602
RevisionCacheOptions: &RevisionCacheOptions{
@@ -2614,6 +2650,9 @@ func TestEvictionOfRevIDKeysWhenNoItemInCVMap(t *testing.T) {
26142650
}
26152651

26162652
func TestEvictionOfCVKeysWhenNoItemInRevMap(t *testing.T) {
2653+
if base.TestDisableRevCache() {
2654+
t.Skip("test requires rev cache enabled for eviction to run")
2655+
}
26172656
db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
26182657
OldRevExpirySeconds: base.DefaultOldRevExpirySeconds,
26192658
RevisionCacheOptions: &RevisionCacheOptions{
@@ -2681,6 +2720,9 @@ func TestEvictionOfCVKeysWhenNoItemInRevMap(t *testing.T) {
26812720

26822721
func TestBasicLoadBackupRevCacheOnlyPopulateOneMap(t *testing.T) {
26832722

2723+
if base.TestDisableRevCache() {
2724+
t.Skip("test requires rev cache enabled")
2725+
}
26842726
db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{
26852727
OldRevExpirySeconds: base.DefaultOldRevExpirySeconds,
26862728
RevisionCacheOptions: &RevisionCacheOptions{
@@ -2741,6 +2783,9 @@ func TestBasicLoadBackupRevCacheOnlyPopulateOneMap(t *testing.T) {
27412783
}
27422784

27432785
func TestItemResidentInCacheBackupRevLoaded(t *testing.T) {
2786+
if base.TestDisableRevCache() {
2787+
t.Skip("test requires rev cache enabled")
2788+
}
27442789
testCases := []struct {
27452790
name string
27462791
useRevID bool

db/util_testing.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ func AddOptionsFromEnvironmentVariables(dbcOptions *DatabaseContextOptions) {
573573
if base.TestsDisableGSI() {
574574
dbcOptions.UseViews = true
575575
}
576+
577+
if base.TestDisableRevCache() {
578+
if dbcOptions.RevisionCacheOptions == nil {
579+
dbcOptions.RevisionCacheOptions = DefaultRevisionCacheOptions()
580+
}
581+
dbcOptions.RevisionCacheOptions.MaxItemCount = 0
582+
}
576583
}
577584

578585
// SetupTestDBWithOptions creates an online test db with the specified database context options. Note that environment variables will override values (SG_TEST_USE_XATTRS, SG_TEST_USE_DEFAULT_COLLECTION).

jenkins-integration-build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ if [ "${TEST_DEBUG:-}" == "true" ]; then
7474
export SG_TEST_BUCKET_POOL_DEBUG="true"
7575
fi
7676

77+
if [ "${DISABLE_REV_CACHE:-}" == "true" ]; then
78+
export SG_TEST_DISABLE_REV_CACHE="true"
79+
fi
80+
7781
if [ "${TARGET_TEST}" != "ALL" ]; then
7882
GO_TEST_FLAGS+=(-run "${TARGET_TEST}")
7983
fi

rest/api_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,6 +3401,9 @@ func TestHLVUpdateOnRevReplicatorPut(t *testing.T) {
34013401
}
34023402

34033403
func TestDocCRUDWithCV(t *testing.T) {
3404+
if base.TestDisableRevCache() {
3405+
t.Skip("Test requires revision cache to be enabled, fetches older revisions expecting to be resident in cache")
3406+
}
34043407
rt := NewRestTester(t, nil)
34053408
defer rt.Close()
34063409

0 commit comments

Comments
 (0)