testcontainers_rs/wait.rs
1use tokio::time::Duration;
2
3/// Represents a condition that needs to be met before a container is considered ready.
4#[derive(Debug, Eq, PartialEq, Clone)]
5pub enum WaitFor {
6 /// An empty condition. Useful for default cases or fallbacks.
7 Nothing,
8 /// Wait for a message on the stdout stream of the container's logs.
9 StdOutMessage { message: String },
10 /// Wait for a message on the stderr stream of the container's logs.
11 StdErrMessage { message: String },
12 /// Wait for a certain amount of time.
13 Duration { length: Duration },
14 /// Wait for the container's status to become `healthy`.
15 Healthcheck,
16}
17
18impl WaitFor {
19 pub fn message_on_stdout<S: Into<String>>(message: S) -> WaitFor {
20 WaitFor::StdOutMessage {
21 message: message.into(),
22 }
23 }
24
25 pub fn message_on_stderr<S: Into<String>>(message: S) -> WaitFor {
26 WaitFor::StdErrMessage {
27 message: message.into(),
28 }
29 }
30
31 pub fn seconds(length: u64) -> WaitFor {
32 WaitFor::Duration {
33 length: Duration::from_secs(length),
34 }
35 }
36
37 pub fn millis(length: u64) -> WaitFor {
38 WaitFor::Duration {
39 length: Duration::from_millis(length),
40 }
41 }
42
43 // pub fn millis_in_env_var(name: &'static str) -> WaitFor {
44 // let additional_sleep_period = var(name).map(|value| value.parse());
45
46 // (|| {
47 // let length = additional_sleep_period.ok()?.ok()?;
48
49 // Some(WaitFor::Duration {
50 // length: Duration::from_millis(length),
51 // })
52 // })()
53 // .unwrap_or(WaitFor::Nothing)
54 // }
55}