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: testcontainers.core.waiting_utils.wait_for_logs keeps waiting despite the container has exited. #681

Open
ArthurBook opened this issue Aug 14, 2024 · 0 comments

Comments

@ArthurBook
Copy link
Contributor

Describe the bug

The testcontainers.core.waiting_utils.wait_for_logs keeps waiting despite the container has exited. This can be confusing if there is a long wait time.

To Reproduce

from testcontainers.core import container, waiting_utils

if __name__ == "__main__":
    waiting_utils.wait_for_logs(
        container.DockerContainer("flyway/flyway").start(),
        r"Successfully applied \d+ migrations to schema",
        timeout=large_n, # 
    )

# >> Raised Exception has occurred: TimeoutError Container did not emit logs satisfying predicate in `large_n` seconds

Runtime environment

Python:         3.11.9
testcontainers  4.7.2
Implementation: CPython
alexanderankin pushed a commit that referenced this issue Aug 14, 2024
Addresses my suggestion made in [issue
681](#681).

This PR adds a flag that checks is the status is not `running` and
raises a `RuntimeError` to avoid waiting for logs after the container
already has exited. The idea is to save wait time when there is a long
startup time in case the container fails early.


```python
from testcontainers.core import container, waiting_utils

if __name__ == "__main__":
    waiting_utils.wait_for_logs(
        container.DockerContainer("flyway/flyway").start(),
        r"Successfully applied \d+ migrations to schema",
        timeout=10,
        raise_on_exit=True,
    )

# > RuntimeError(f"Container exited before emitting logs satisfying predicate")
# ( Raised almost immediately ) 
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant