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

[Bug]: Fail-fast of wait.LogStrategy doesn't work properly #1302

Closed
frozenbonito opened this issue Jun 23, 2023 · 1 comment · Fixed by #1304
Closed

[Bug]: Fail-fast of wait.LogStrategy doesn't work properly #1302

frozenbonito opened this issue Jun 23, 2023 · 1 comment · Fixed by #1304
Labels
bug An issue with the library

Comments

@frozenbonito
Copy link
Contributor

Testcontainers version

0.21.0

Using the latest Testcontainers version?

Yes

Host OS

Linux (WSL2)

Host arch

x86

Go version

1.20.5

Docker version

Client: Docker Engine - Community
 Cloud integration: v1.0.33
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:52:17 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Desktop
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:52:17 2023
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client: Docker Engine - Community
 Version:    24.0.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.5
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.18.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.19
    Path:     /usr/local/lib/docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.4
    Path:     /usr/local/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-scan
  scout: Command line tool for Docker Scout (Docker Inc.)
    Version:  v0.12.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-scout
WARNING: Plugin "/usr/libexec/docker/cli-plugins/docker-app" is not valid: failed to fetch metadata: fork/exec /usr/libexec/docker/cli-plugins/docker-app: no such file or directory

Server:
 Containers: 6
  Running: 3
  Paused: 0
  Stopped: 3
 Images: 23
 Server Version: 24.0.2
 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: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 3.828GiB
 Name: docker-desktop
 ID: 6b62848a-51a8-4f7e-9859-9d3804a6b081
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 65
  Goroutines: 79
  System Time: 2023-06-23T12:50:20.924306614Z
  EventsListeners: 10
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: true
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

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?

In the following code, mysql container immediately stops due to missing environment variables.

package main_test

import (
	"context"
	"testing"

	"github.com/testcontainers/testcontainers-go"
	"github.com/testcontainers/testcontainers-go/wait"
)

func TestLogStrategy(t *testing.T) {
	ctx := context.Background()

	req := testcontainers.ContainerRequest{
		Image:        "mysql:8.0",
		ExposedPorts: []string{"3306/tcp", "33060/tcp"},
		Env: map[string]string{
			"MYSQL_USER":     "user",
			"MYSQL_PASSWORD": "password",
			"MYSQL_DATABASE": "db",
			// "MYSQL_ALLOW_EMPTY_PASSWORD": "yes",
		},
		WaitingFor: wait.ForLog("port: 3306  MySQL Community Server"),
	}

	container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
		ContainerRequest: req,
		Started:          true,
	})
	if err != nil {
		t.Fatal(err)
	}
	defer container.Terminate(ctx)
}

In this case, LogStrategy should detect the container stop and immediately return an error(#944).
However, it keeps waiting until timeout actually.

Relevant log output

$ go test -run TestLogStrategy .
2023/06/23 22:01:04 github.com/testcontainers/testcontainers-go - Connected to docker: 
  Server Version: 24.0.2
  API Version: 1.42
  Operating System: Docker Desktop
  Total Memory: 3919 MB
2023/06/23 22:01:04 🐳 Creating container for image docker.io/testcontainers/ryuk:0.5.1
2023/06/23 22:01:04 ✅ Container created: e8fa2cbc17de
2023/06/23 22:01:04 🐳 Starting container: e8fa2cbc17de
2023/06/23 22:01:05 ✅ Container started: e8fa2cbc17de
2023/06/23 22:01:05 🚧 Waiting for container id e8fa2cbc17de image: docker.io/testcontainers/ryuk:0.5.1. Waiting for: &{Port:8080/tcp timeout:<nil> PollInterval:100ms}
2023/06/23 22:01:05 🐳 Creating container for image mysql:8.0
2023/06/23 22:01:05 ✅ Container created: 17873a259230
2023/06/23 22:01:05 🐳 Starting container: 17873a259230
2023/06/23 22:01:06 ✅ Container started: 17873a259230
2023/06/23 22:01:06 🚧 Waiting for container id 17873a259230 image: mysql:8.0. Waiting for: &{timeout:<nil> Log:port: 3306  MySQL Community Server Occurrence:1 PollInterval:100ms}
2023/06/23 22:02:06 container logs:
2023-06-23 13:01:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
2023-06-23 13:01:06+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2023-06-23 13:01:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
2023-06-23 13:01:06+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
    You need to specify one of the following as an environment variable:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD

--- FAIL: TestLogStrategy (61.55s)
    log_strategy_test.go:31: context deadline exceeded: failed to start container
FAIL
FAIL    frozenbonito/testcontainers-test        61.549s
FAIL

Additional information

@frozenbonito frozenbonito added the bug An issue with the library label Jun 23, 2023
@mdelapenya
Copy link
Collaborator

Regarding the test case provided in the issue, it's wrong in the sense that it's not honouring the desired state of the container. In that sense not only the log strategy but all of them should detect that state the soonest. I did check that (see #1304 (comment)) and we do it everywhere else but in the log strategy. Please see my comment for a plausible and different fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants