fix(nats): use wait for listening port instead of wait for log#3256
fix(nats): use wait for listening port instead of wait for log#3256mdelapenya merged 3 commits intotestcontainers:mainfrom
Conversation
less error prone log message
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
modules/nats/nats.go
Outdated
| ExposedPorts: []string{defaultClientPort, defaultRoutingPort, defaultMonitoringPort}, | ||
| Cmd: []string{"-DV", "-js"}, | ||
| WaitingFor: wait.ForLog("Listening for client connections on 0.0.0.0:4222"), | ||
| WaitingFor: wait.ForLog("Server is ready"), |
There was a problem hiding this comment.
suggestion: instead of relying on the log message, we should replace it with a wait for the listening port, which is more deterministic; besides we are more into using the wait for listening port strategy more and more. Thoughts?
There was a problem hiding this comment.
yeah, i noticed the listen port strategy is being used more and more in the project. still, i can imagine (hypothetically) a case where the listener comes up for a second and then the server crashes. do you think we better combine both or just keep wait for port?
WaitingFor: wait.ForAll(
wait.ForListeningPort(defaultClientPort),
wait.ForLog("Server is ready"),
)
|
good catch! |
stevenh
left a comment
There was a problem hiding this comment.
Thanks for this, waiting on the port is positive change which we've been doing in other places. However, do we actually need the ForLog still or is ForListeningPort good enough?
yup, just checked and just the port check seems to be sufficient! |
mdelapenya
left a comment
There was a problem hiding this comment.
@own2pwn LGTM, I'll merge it once the CI passes.
Thank you so much for your contribution, it makes the project much better 👏
* main: (33 commits) feat(registry): add helper functions to pull and tag images (testcontainers#3275) fix(reaper): remove termSignal override (testcontainers#3261) chore(deps): bump ryuk to v0.13.0, which uses scratch as base image (testcontainers#3274) chore(release): refine release script to update inter-module dependencies (testcontainers#3273) fix(registry): update `WithHtpasswd` to use `os.CreateTemp` instead of `os.Create` with `filepath.Join`. (testcontainers#3272) chore(deps): bump github.com/docker/docker from 28.2.2+incompatible to 28.3.3+incompatible (testcontainers#3270) chore(postgres): use require.NotNil instead of assert.NotNil (testcontainers#3252) fix(nats): use wait for listening port instead of wait for log (testcontainers#3256) chore(deps): bump github.com/go-viper/mapstructure/v2 (testcontainers#3267) fix(postgres): snapshot restore (testcontainers#3264) fix(dockermcpgateway): use duckduckgo instead of brave (testcontainers#3247) feat: add Solace pubsub+ module (testcontainers#3230) feat(options): add WithProvider (testcontainers#3241) chore(deps): bump github/codeql-action from 3.29.2 to 3.29.3 (testcontainers#3237) chore(deps): bump golang.org/x/oauth2 in /modules/weaviate (testcontainers#3240) chore(deps): bump mkdocs-include-markdown-plugin from 7.1.5 to 7.1.6 (testcontainers#3239) chore(deps): bump requests from 2.32.0 to 2.32.4 (testcontainers#3204) feat(mcpgateway): add MCP gateway module (testcontainers#3232) chore(deps): bump golang.org/x/oauth2 in /modules/pulsar (testcontainers#3236) chore(deps): bump golang.org/x/oauth2 in /modules/gcloud (testcontainers#3235) ...
* main: (30 commits) fix: preserve unix socket schema in testcontainers host from properties (testcontainers#3213) feat(registry): add helper functions to pull and tag images (testcontainers#3275) fix(reaper): remove termSignal override (testcontainers#3261) chore(deps): bump ryuk to v0.13.0, which uses scratch as base image (testcontainers#3274) chore(release): refine release script to update inter-module dependencies (testcontainers#3273) fix(registry): update `WithHtpasswd` to use `os.CreateTemp` instead of `os.Create` with `filepath.Join`. (testcontainers#3272) chore(deps): bump github.com/docker/docker from 28.2.2+incompatible to 28.3.3+incompatible (testcontainers#3270) chore(postgres): use require.NotNil instead of assert.NotNil (testcontainers#3252) fix(nats): use wait for listening port instead of wait for log (testcontainers#3256) chore(deps): bump github.com/go-viper/mapstructure/v2 (testcontainers#3267) fix(postgres): snapshot restore (testcontainers#3264) fix(dockermcpgateway): use duckduckgo instead of brave (testcontainers#3247) feat: add Solace pubsub+ module (testcontainers#3230) feat(options): add WithProvider (testcontainers#3241) chore(deps): bump github/codeql-action from 3.29.2 to 3.29.3 (testcontainers#3237) chore(deps): bump golang.org/x/oauth2 in /modules/weaviate (testcontainers#3240) chore(deps): bump mkdocs-include-markdown-plugin from 7.1.5 to 7.1.6 (testcontainers#3239) chore(deps): bump requests from 2.32.0 to 2.32.4 (testcontainers#3204) feat(mcpgateway): add MCP gateway module (testcontainers#3232) chore(deps): bump golang.org/x/oauth2 in /modules/pulsar (testcontainers#3236) ...
What does this PR do?
Updates the WaitingFor condition in test containers from
to
Why is it important?
The previous log message indicated only that the server had started, which might occur before the listener is ready to handle all operations.
wait.ForListeningPort(defaultClientPort),is a clearer signal that the nats server startup process has completed, providing a more accurate readiness check.