Skip to content

Improve logging for WaitStrategies (e.g. HostPortWaitStrategy) to aid debugging #10780

@bhawnapannu2701

Description

@bhawnapannu2701

Currently, some WaitStrategy implementations (for example HostPortWaitStrategy) provide very limited information when container startup fails.
For developers running integration tests, this makes debugging difficult because logs don’t indicate which port or condition failed.

Proposal:

1.Add a more descriptive toString() implementation to WaitStrategy classes.

2.Include key configuration details (e.g. target port, retries, timeout) in the string.

3.Ensure these details appear in logs when wait strategy fails.

Benefits:

1.Improves developer experience when using Testcontainers.

2.Provides clear context in logs without changing core functionality.

3.Small, non-breaking change that helps in debugging test failures.

Scope:

1.Modify HostPortWaitStrategy (and optionally other WaitStrategy classes where toString() is missing or vague).

2.Add a unit test that verifies the toString() output contains expected fields.

Example Log Improvement

Current :-
org.testcontainers.containers.wait.strategy.WaitUntilReady: Wait failed

Proposed :-
org.testcontainers.containers.wait.strategy.HostPortWaitStrategy{port=5432, timeout=60s, retries=10} - Wait failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions