Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Couchbase containers intermittently hang on startup #2650

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions modules/couchbase/couchbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,14 @@ func (c *CouchbaseContainer) createPrimaryIndex(ctx context.Context, bucket buck
body := map[string]string{
"statement": "CREATE PRIMARY INDEX on `" + bucket.name + "`",
}

_, err := c.doHttpRequest(ctx, QUERY_PORT, "/query/service", http.MethodPost, body, true)

err := backoff.Retry(func() error {
response, err := c.doHttpRequest(ctx, QUERY_PORT, "/query/service", http.MethodPost, body, true)
firstError := gjson.Get(string(response), "errors.0.code").Int()
if firstError != 0 {
return errors.New("index creation failed")
}
return err
}, backoff.WithContext(backoff.NewExponentialBackOff(), ctx))
return err
}

Expand Down
12 changes: 10 additions & 2 deletions modules/couchbase/couchbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const (
// dockerImages {
enterpriseEdition = "couchbase:enterprise-7.1.3"
enterpriseEdition = "couchbase:enterprise-7.6.1"
communityEdition = "couchbase:community-7.1.1"
// }
)
Expand Down Expand Up @@ -54,7 +54,15 @@ func TestCouchbaseWithEnterpriseContainer(t *testing.T) {
ctx := context.Background()

bucketName := "testBucket"
container, err := tccouchbase.Run(ctx, enterpriseEdition, tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName)))
bucket := tccouchbase.NewBucket(bucketName).
WithQuota(100).
WithReplicas(0).
WithFlushEnabled(true).
WithPrimaryIndex(true)
container, err := tccouchbase.Run(ctx,
enterpriseEdition,
tccouchbase.WithBuckets(bucket),
)
if err != nil {
t.Fatal(err)
}
Expand Down