dockertest/waitfor/mod.rs
1//! Contains `WaitFor` trait used to determine when a PendingContainer has started
2//! and all the default implementations of it.
3
4use crate::container::{OperationalContainer, PendingContainer};
5use crate::docker::ContainerState;
6use crate::DockerTestError;
7
8pub use async_trait::async_trait;
9use dyn_clone::DynClone;
10
11mod message;
12mod nowait;
13mod status;
14
15pub(crate) use message::wait_for_message;
16pub use message::{MessageSource, MessageWait};
17pub use nowait::NoWait;
18pub use status::{ExitedWait, RunningWait};
19
20/// Trait to wait for a container to be ready for service.
21#[async_trait]
22pub trait WaitFor: Send + Sync + DynClone + std::fmt::Debug {
23 /// Method implementation should return a future that resolves once the condition
24 /// described by the implementing structure is fulfilled. Once this successfully resolves,
25 /// the container is marked as ready.
26 ///
27 // TODO: Implement error propagation with the container id that failed for cleanup
28 async fn wait_for_ready(
29 &self,
30 container: PendingContainer,
31 ) -> Result<OperationalContainer, DockerTestError>;
32
33 /// What state the container is expected to be in after completing the `wait_for_ready` method,
34 /// defaulting to the `ContainerState::Running` state.
35 /// NOTE: This is only relevant for the container state api on 'OperationalContainer' (start, stop,
36 /// kill) as we deny certain operations based on the assumed container state.
37 fn expected_state(&self) -> ContainerState {
38 ContainerState::Running
39 }
40}
41
42dyn_clone::clone_trait_object!(WaitFor);