Skip to content

Commit

Permalink
Support SG_TEST_USE_EXISTING_BUCKET
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin committed Feb 5, 2025
1 parent 27b1b4b commit abb7c9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
24 changes: 7 additions & 17 deletions base/main_test_bucket_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,6 @@ func NewTestBucketPoolWithOptions(ctx context.Context, bucketReadierFunc TBPBuck
if numCollectionsPerBucket == 0 {
numCollectionsPerBucket = tbpNumCollectionsPerBucket(ctx)
}
// We can safely skip setup when we want Walrus buckets to be used.
// They'll be created on-demand via GetTestBucketAndSpec,
// which is fast enough for Walrus that we don't need to prepare buckets ahead of time.
if !TestUseCouchbaseServer() || TestUseExistingBucket() {
tbp := TestBucketPool{
bucketInitFunc: bucketInitFunc,
unclosedBuckets: make(map[string]map[string]struct{}),
integrationMode: TestUseCouchbaseServer(),
useExistingBucket: TestUseExistingBucket(),
useDefaultScope: options.UseDefaultScope,
numCollectionsPerBucket: numCollectionsPerBucket,
}
tbp.verbose.Set(tbpVerbose())
return &tbp
}

// Used to manage cancellation of worker goroutines
ctx, ctxCancelFunc := context.WithCancel(ctx)
Expand All @@ -132,6 +117,13 @@ func NewTestBucketPoolWithOptions(ctx context.Context, bucketReadierFunc TBPBuck
useDefaultScope: options.UseDefaultScope,
skipMobileXDCR: true, // do not set up enableCrossClusterVersioning until Sync Gateway 4.x
numCollectionsPerBucket: numCollectionsPerBucket,
verbose: *NewAtomicBool(tbpVerbose()),
}

// We can safely skip setup if using existing buckets or rosmar buckets, since they can be opened on demand.
if UnitTestUrlIsWalrus() || TestUseExistingBucket() {
tbp.stats.TotalBucketInitCount.Add(int32(numBuckets))
return &tbp
}

tbp.cluster = newTestCluster(ctx, UnitTestUrl(), &tbp)
Expand All @@ -142,8 +134,6 @@ func NewTestBucketPoolWithOptions(ctx context.Context, bucketReadierFunc TBPBuck
}
tbp.skipCollections = !useCollections

tbp.verbose.Set(tbpVerbose())

// Start up an async readier worker to process dirty buckets
go tbp.bucketReadierWorker(ctx, bucketReadierFunc)

Expand Down
4 changes: 4 additions & 0 deletions base/main_test_bucket_pool_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func (tbp *TestBucketPool) canUseNamedCollections(ctx context.Context) (bool, er

// tbpNumBuckets returns the configured number of buckets to use in the pool.
func tbpNumBuckets(ctx context.Context) int {
if TestUseExistingBucket() {
// SG_TEST_USE_EXISTING_BUCKET only allows for one bucket name
return 1
}
numBuckets := tbpDefaultBucketPoolSize
if envPoolSize := os.Getenv(tbpEnvBucketPoolSize); envPoolSize != "" {
var err error
Expand Down

0 comments on commit abb7c9b

Please sign in to comment.