testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.73k stars 266 forks source link

[Bug]: Unable run Couchbase test container on latest version #1240

Closed fasilmarshooq closed 1 week ago

fasilmarshooq commented 2 weeks ago

Testcontainers version

3.9.0

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host arch

x64

.NET version

8.0

Docker version

Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:07:41 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:07:41 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.26
  GitCommit:        3dd1e886e55dd695541fdcd67420c2888645a495
 runc:
  Version:          1.1.10
  GitCommit:        v1.1.10-0-g18a0cb0
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client: Docker Engine - Community
 Version:    24.0.7
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.5
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 9
  Running: 2
  Paused: 0
  Stopped: 7
 Images: 110
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dd1e886e55dd695541fdcd67420c2888645a495
 runc version: v1.1.10-0-g18a0cb0
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.15.133.1-microsoft-standard-WSL2
 Operating System: Ubuntu 22.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 9.718GiB
 Name: 5HX0SQ3
 ID: 711be3e5-278d-4359-9a71-7a4eb4d4f1f7
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
         Access to the remote API is equivalent to root access on the host. Refer
         to the 'Docker daemon attack surface' section in the documentation for
         more information: https://docs.docker.com/go/attack-surface/
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

What happened?

{"ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":{},"InnerException":null,"HelpURL":null,"StackTraceString":"   at Couchbase.Diagnostics.DiagnosticsReportProvider.CreatePingReportAsync(ClusterContext context, BucketConfig config, PingOptions options)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"Couchbase.NetClient","WatsonBuckets":null}

Relevant log output

{"ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":{},"InnerException":null,"HelpURL":null,"StackTraceString":"   at Couchbase.Diagnostics.DiagnosticsReportProvider.CreatePingReportAsync(ClusterContext context, BucketConfig config, PingOptions options)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"Couchbase.NetClient","WatsonBuckets":null}

Additional information

HofmeisterAn commented 2 weeks ago

Which version (tag) did you use exactly? I tested community-7.6.2 and latest, and I did not run into any issues. I think latest refers to the enterprise version, which is not specifically supported or tested.

fasilmarshooq commented 1 week ago

The current unit test doesnt point to any version , so i think its pointing to latest.

fasilmarshooq commented 1 week ago

i face the same issue even with the community edition

private readonly CouchbaseContainer _couchbaseContainer = new CouchbaseBuilder()
    .WithImage("couchbase:community-7.6.2")
    .Build();
fasilmarshooq commented 1 week ago

Working with default testContainers but not with CoucheBase module


using Couchbase;
using Couchbase.Management.Buckets;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;

namespace testCoucheBase
{
    public class Tests
    {
        private IContainer _couchbaseContainer;
        private const string Username = "Administrator";
        private const string Password = "password";
        private const string BucketName = "YCS";

        [OneTimeSetUp]
        public async Task SetupAsync()
        {
            // Configure the Couchbase container
            _couchbaseContainer = new ContainerBuilder()
                .WithImage("couchbase:community-7.6.2")
                .WithEnvironment("CB_USERNAME", Username)
                .WithEnvironment("CB_PASSWORD", Password)
                .WithPortBinding(8091, 8091)
                .WithPortBinding(8093, 8093)
                .WithPortBinding(11210, 11210)
                .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8091))
                .Build();

            // Start the container
            await _couchbaseContainer.StartAsync();

            // Initialize the cluster
            await _couchbaseContainer.ExecAsync(new[] {
                "couchbase-cli", "cluster-init",
                "--cluster-username", Username,
                "--cluster-password", Password,
                "--services", "data,index,query",
                "--cluster-ramsize", "512",
                "--cluster-index-ramsize", "256"
            });

        }

        [OneTimeTearDown]
        public async Task TearDown()
        {
            await _couchbaseContainer.StopAsync();
            await _couchbaseContainer.DisposeAsync();
        }

        [Test]
        public async Task Test1()
        {

            var clusterOptions = new ClusterOptions
            {
                UserName = Username,
                Password = Password,
                ConnectionString = "couchbase://127.0.0.1" // For some reason not able to connect via localHost since docker is running in wsl and i can access management ui from browser using localHost
            };

            var cluster = await Cluster.ConnectAsync(clusterOptions);

            IBucketManager manager = cluster.Buckets;
            await CreateBucket(manager);

            // Open the default bucket
            var bucket = await manager.GetBucketAsync(BucketName);

            // Perform operations with the bucket...
            Assert.IsNotNull(bucket);
        }

        private static async Task CreateBucket(IBucketManager manager)
        {
            // create a bucket
            var bucketSettings = new BucketSettings();
            bucketSettings.Name = BucketName;
            bucketSettings.BucketType = BucketType.Couchbase;
            bucketSettings.RamQuotaMB = 100;
            await manager.CreateBucketAsync(bucketSettings);
        }
    }
}
fasilmarshooq commented 1 week ago

May be the issue is because the docker is running in wsl and the module is not able to resolve the ports properly ?

HofmeisterAn commented 1 week ago

May be the issue is because the docker is running in wsl and the module is not able to resolve the ports properly ?

Hmm, that is unlikely. I am using WSL as well and tested three different versions, running the tests for a while (on two different devices). None of them encountered a null reference.

// For some reason not able to connect via localHost since docker is running in wsl and i can access management ui from browser using localHost

This is likely due to https://github.com/testcontainers/testcontainers-dotnet/issues/825, but using the provided connection string, we ensure it resolves the correct host and port.

Could you please set a breakpoint at PingAsync(), share the connection string, the container logs, and check if the container is still running? The console should also include a log message that contains the URL to the web interface. Check if you can access it. The log message should look like:

Couchbase container is ready! UI available at http://127.0.0.1:60745/.

fasilmarshooq commented 1 week ago

connection string is couchbase://localhost at the point and yes the container was still running

HofmeisterAn commented 1 week ago

connection string is couchbase://localhost at the point and yes the container was still running

localhost is very likely not correct. According to your environment, it should be 127.0.0.1.

eddumelendez commented 1 week ago

Hi, PTAL at this PR in tc-java

fasilmarshooq commented 1 week ago

tried on one of my colleagues laptop the connection string is properly resolved as 127.0.0.1 , some thing wrong with my machine when bridges to wsl i guess.

fasilmarshooq commented 1 week ago

Thanks for the help mate! , we at Agoda really love your work.