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

Add a wait_for_healthcheck method to DockerCompose #241

Open
csikb opened this issue Aug 28, 2022 · 2 comments
Open

Add a wait_for_healthcheck method to DockerCompose #241

csikb opened this issue Aug 28, 2022 · 2 comments

Comments

@csikb
Copy link

csikb commented Aug 28, 2022

It's possible to check if the healthcheck passed trought the cli.
docker ps --format json will list all the services running and their corresponding healthchecks.

Proposed method signature: compose.wait_for_healthcheck(sec: int = 10)

High level description how it should work:
Iterate trough services check if healthcheck is healthy.
If not: wait and repeat until timeout.

testcontaners java and node has the option to wait for healthcheck. It would be nice if testcontainers-python would have the same funtionality

@rhoban13
Copy link

Ideally this should work for even the DockerContainer as well.

@lukasz-matter
Copy link

A very simple implementation for a DockerContainer can look like this:

    with container:
        start_time = time.time()
        underlying_container = container.get_wrapped_container()
        while time.time() - start_time < 10:
            underlying_container.reload()
            if underlying_container.health == 'healthy':
                print(f"Container is healthy!")
                break
            time.sleep(.1)
        else:
            raise TimeoutError(
                f"Container status is not healthy after 10s - it's {underlying_container.health}!"
            )
        yield container

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

No branches or pull requests

4 participants