testcontainers / testcontainers-go

Testcontainers for Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.
https://golang.testcontainers.org
MIT License
3.5k stars 478 forks source link

`go test -v (etc)` logs only show up after completion after adding testcontainers-go #379

Closed abayer closed 1 year ago

abayer commented 2 years ago

Describe the bug I started to move from using an already-running database to using postgres in a container via testcontainers-go, and when I did, the logs that normally stream to the console when I run go test -v ./... stopped showing up until go test had completed. No === RUN TestGetJVMVersionID etc or anything until it finishes, and then the go test logs all show up at once. This is the case whether I run go test -v ./... or add other flags like -run TestGetJVMVersionID, etc, though interestingly when running individual tests in Goland, the logs do stream.

To Reproduce So...I've tried to create a simple reproduction case, but I have not succeeded. The best I can do is point to the commit in my repo where this started happening - https://github.com/abayer/jenkins-usage-stats/commit/a30e0ecc77388fa36f563bf5442176297bbd4bf9. Note that go test -v ./... run against the previous commit requires the creation of a local database named jenkins_usage_stats and running make migration or they'll fail so quickly you may not be able to tell whether the logs are streaming or just show up at the end. With that commit, you can just run go test -v ./... without any setup.

Note that there were other things changed in that commit, but the go.mod changes are just github.com/beevik/etree moving from an indirect to a direct require, and adding github.com/testcontainers/testcontainers-go and github.com/golang-migrate/migrate/v4. I've verified (by hacking the code around to remove all migrate usages and removing it from go.mod) that github.com/golang-migrate/migrate/v4's presence or absence makes no difference to logs streaming.

The testcontainers-go-related code is in https://github.com/abayer/jenkins-usage-stats/commit/a30e0ecc77388fa36f563bf5442176297bbd4bf9#diff-f8620f9dd4990ddb428e7f3e8ab587b56226b72e77ed1088892a98835f91e589, derived from https://brietsparks.com/testcontainers-golang-db-access/.

Expected behavior go test -v ./... to stream logs, rather than them only showing up on completion? =)

docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
  compose: Docker Compose (Docker Inc., v2.0.0-rc.2)
  scan: Docker Scan (Docker Inc., v0.8.0)
WARNING: Plugin "/Users/abayer/.docker/cli-plugins/docker-app" is not valid: failed to fetch metadata: fork/exec /Users/abayer/.docker/cli-plugins/docker-app: no such file or directory

Server:
 Containers: 75
  Running: 0
  Paused: 0
  Stopped: 75
 Images: 622
 Server Version: 20.10.8
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  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 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e25210fe30a0a703442421b0f60afac609f950a3
 runc version: v1.0.1-0-g4144b63
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.47-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.64GiB
 Name: docker-desktop
 ID: H5IB:DBQJ:JUII:MBDN:NY4F:T3WR:2BVZ:GOQL:V43L:TVZU:YDFH:QXAX
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 44
  Goroutines: 47
  System Time: 2021-11-12T20:32:06.28588511Z
  EventsListeners: 4
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: true
 Insecure Registries:
  host.docker.local:5000
  127.0.0.0/8
 Live Restore Enabled: false

Additional context I am using go1.17, though I have a feeling that won't make a difference, and have reproduced this on MacOS and Ubuntu 20.04. And yes, I know that my package layout is janky - I need to fix that. =) Also, I'll keep trying to put together a simpler, smaller reproduction case.

mdelapenya commented 2 years ago

Hey @abayer did you manage to create a smaller reproduction case? I won't have time to look at this until Christmas break, so having that would help me a lot in clarifying what's going on.

fiftin commented 2 years ago

@abayer , @mdelapenya

Need more info by issue. It is impossible to reproduce by that description.

mdelapenya commented 2 years ago

@abayer , @mdelapenya

Need more info by issue. It is impossible to reproduce by that description.

Indeed. @abayer would you mind explaining it a little more what is the use case you described? Could it be that you are lacking container logs when running your own tests?

mdelapenya commented 1 year ago

I'm closing this issue as stale. Please feel free to reopen if needed.

Thanks in advance