Skip to content

Conversation

@HofmeisterAn
Copy link
Collaborator

@HofmeisterAn HofmeisterAn commented Oct 13, 2025

What does this PR do?

This PR introduces wait strategy modes. Wait strategy modes define how Testcontainers for .NET handles wait strategies. Normally, a wait strategy indicates when a container (and the service inside it) is ready to use. These strategies assume the container stays running.

However, sometimes a container fails to start and exits during startup. In those cases, Testcontainers kept retrying the wait strategy indefinitely, never indicating readiness. From a developer's point of view, it looks like the container startup is just hanging.

This PR updates the internal behavior of wait strategies. They now expect the container to be running. If the container exits unexpectedly, Testcontainers for .NET will collect the exit code and logs, then throw a meaningful exception: ContainerNotRunningException, which includes that information.

Some scenarios do not require the container to stay running. For example, running database migrations in a sidecar container during startup. In those cases, it is fine if the container exits after finishing its work. To support this, Testcontainers for .NET now provides wait strategy modes.

If you do not want an exception when a container exits unexpectedly, set the wait strategy mode to OneShot.

TODOs

  • Add integration tests.
  • Add docs.

Why is it important?

-

Related issues

@HofmeisterAn HofmeisterAn added enhancement New feature or request breaking change Causing compatibility issues labels Oct 13, 2025
@netlify
Copy link

netlify bot commented Oct 13, 2025

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 2adad5e
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/68ee8d36d55a3600084aee23
😎 Deploy Preview https://deploy-preview-1550--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@HofmeisterAn HofmeisterAn marked this pull request as ready for review October 14, 2025 17:50
@HofmeisterAn HofmeisterAn merged commit c2b86ad into develop Oct 15, 2025
139 checks passed
@HofmeisterAn HofmeisterAn deleted the feature/throw-if-contianer-not-running branch October 15, 2025 09:52
@0xced
Copy link
Contributor

0xced commented Oct 16, 2025

Thanks for taking the time to address this issue, Andre!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Causing compatibility issues enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Wait strategies should detect when a container exits early and throw an exception

3 participants