DependsOn Support: Design Discussion #2042
Replies: 3 comments 8 replies
-
I completely agree with the proposed implementation of handling I think handling dependency cycles is a nice to have unless it's particularly easy to foot-gun yourself. the Current proposed implementation makes any footguns arduous to negligently discharge, so I don't think it's required to have, but would be nice to have. We could implement a DFS/disjoint set cycle detection if need be, but I don't think it need be. While the exception/error path handling for cyclical dependencies is not mentioned, I'm fine with either returning a golang error or even just logging an error/warning to stderr if we feel it worthy to implement upfront. That said, I would not personally consider cyclical dependency avoidance required functionality given the overall context of this issue and currently proposed implementation. |
Beta Was this translation helpful? Give feedback.
-
Please take a look at #1922, where we propose a new lifecycle event: Ready, the wait strategies are moved there. But I think it does not affect the discussion here, as the |
Beta Was this translation helpful? Give feedback.
-
After discussing
The depends on interface will look similar to the following: dependencies := testcontainers.NewContainerDependencies(reqDepA, reqDepB)
req := testcontainers.ContainerRequest{
// ..options
DependsOn: dependencies
}
// start parent container with req. Question up for discussion:
|
Beta Was this translation helpful? Give feedback.
-
Context
This design discussion aims to solve how
DependsOn
would be implemented such that it complies with the following behaviour:wait.Strategy
.Currently, users must manually sequence the startup order or depend on Docker Compose for a cluster of dependent containers. The addition of the
DependsOn
option would eliminate this manual effort.Design Option
Extending DependsOn as a Wait Strategy
Initially I considered adding
DependsOn
as a type of wait strategy such that interfacing with DependsOn would be familiar to other (similar) waiting strategies. However, in closer observation it seems thatwait.Strategy
describes the post-startup phase of the container lifecycle while DependsOn concerns itself with pre-startup.I think it's still feasible to add DependsOn as a wait strategy, but that would require a fundamental change with how wait strategies are understood.
Adding DependsOn option to ContainerRequest
Addition of
DependsOn
to theContainerRequest
which would be used to supply the list of dependant containers that must run prior to itself.DependsOn should then be included as part of the pre-startup lifecycle and each dependant container is waited on according to their respective wait strategies. Only if all dependency are ready will the container move forward with starting itself.
Handling Cyclical Dependencies
Cyclical dependency are considered as errors and should cause startup to fail. To prevent side-effects, dependency-cycles should be detected before any attempts are made to start dependency containers.
Detection would follow a straight forward depth (or breadth) search that maintains a record of visited dependencies. If a container is revisited during the search (signalling a cyclical dependency) an error is triggered, and no containers are started.
Related Issues
Beta Was this translation helpful? Give feedback.
All reactions