TestContainer - Service n1ql is either not configured or cannot be reached. Check logs for details

I am using the latest .Net SDK and TestContainers to do integration testing and all works perfectly until I try to use a query and then I get the following error:

Service n1ql is either not configured or cannot be reached. Check logs for details.

Code for container setup is pretty straight forward:

CouchbaseContainer = new Testcontainers.Couchbase.CouchbaseBuilder()
            .WithImage("couchbase/server:latest")
            .WithHostname("localhost")
            .WithPortBinding(8091, 8091)
            .WithPortBinding(8093, 8093)
            .WithPortBinding(8094, 8094)
            .Build();
        
        await CouchbaseContainer.StartAsync();

With or without port bindings has not made a difference.

Creating a bucket if it does not exist, which is the case each time the TestContainer is run:

 var bucketManager = cluster.Buckets;
        var buckets = await bucketManager.GetAllBucketsAsync();
        
        if (!buckets.ContainsKey(settings.BucketName))
        {
            var bucketSettings = new BucketSettings
            {
                Name = settings.BucketName,
                BucketType = BucketType.Couchbase,
                RamQuotaMB = 100,
                FlushEnabled = true,
                NumReplicas = 1,
                ReplicaIndexes = true
            };
            
            await bucketManager.CreateBucketAsync(bucketSettings);

I am just not sure, where or how to make sure the N1QL services is setup for my bucket.

Looking at GitHub:

It seems they enable all of the required services automatically:

 static CouchbaseBuilder()
    {
        EnabledServices.Add(CouchbaseService.Data);
        EnabledServices.Add(CouchbaseService.Index);
        EnabledServices.Add(CouchbaseService.Query);
        EnabledServices.Add(CouchbaseService.Search);
    }

Anyone else have or solve this problem?

1 Like

I only have a guess here - can you add a 60 second wait before trying to create the bucket? (which uses n1ql) (Alternatively, loop on it until success, with a 1 second wait…)

I originally had a 500ms sleep after creating the bucket which was solving my connection issues, bumping this to 2s solved this issue as well.

Thanks for the help :grinning:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.