testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

feat : Add support for depends_on functionality

Open hari134 opened this issue 1 year ago • 4 comments

Description:

This PR addresses issue #679 by introducing the depends_on functionality to DockerContainer, enhancing feature parity with the dependsOn functionality in TC-java by allowing containers to define dependencies. With this feature, a container can now specify dependencies on other containers, ensuring they will only start once all dependencies reach the running state.

Changes

  • Added a depends_on method to define dependencies between containers.

  • Implemented _start_dependencies to manage recursive startup and ensure each dependency reaches the running state.

  • Integrated exception handling for cleanup, ensuring that all dependencies are stopped if a failure occurs during the startup process.

Sample Usage

from testcontainers.core.container import DockerContainer

db_container = DockerContainer("mysql:latest").with_command("tail -f /dev/null")
app_container = DockerContainer("myapp:latest").with_command("tail -f /dev/null").depends_on(db_container)

app_container.start()

app_container.stop()
db_container.stop()

Testing

Added test cases to verify:

  • Complete cleanup when all dependencies fail to start.

  • Cleanup of all dependencies when some dependencies succeed, and others fail.

  • Ensuring the main container does not start if any dependency fails.

hari134 avatar Oct 26 '24 13:10 hari134

Hi, just checking in on this PR. I’d be happy to make adjustments if needed. Please let me know if there’s anything I can do to help move this forward. Thanks!

hari134 avatar Nov 01 '24 11:11 hari134

@hari134 currently the priorities that I have for the project are making the core parts of it work correctly, rather than adding features (as its a high potential to need to be re-done later). I plan on doing another big push to move the project before the end of the year but not sure when. usually more downtime during holiday season, so this may get merged then.

alexanderankin avatar Nov 01 '24 12:11 alexanderankin

@alexanderankin I completely understand the focus on stabilizing the core functionality before adding new features. I'll address the issues raised, and you can review them whenever it's convenient. Thanks.

hari134 avatar Nov 01 '24 15:11 hari134

@alexanderankin is this ready to merge or are there any changes to be made?

hari134 avatar Feb 07 '25 19:02 hari134