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

feat!: add container startup timeout with default of 1 minute #643

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions testcontainers/src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub enum WaitContainerError {
HealthCheckNotConfigured(String),
#[error("container is unhealthy")]
Unhealthy,
#[error("container startup timeout")]
StartupTimeout,
}

impl TestcontainersError {
Expand Down
17 changes: 16 additions & 1 deletion testcontainers/src/core/image/runnable_image.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::BTreeMap, net::IpAddr};
use std::{collections::BTreeMap, net::IpAddr, time::Duration};

use crate::{
core::{mounts::Mount, ContainerState, ExecCommand, WaitFor},
Expand All @@ -23,6 +23,7 @@
shm_size: Option<u64>,
cgroupns_mode: Option<CgroupnsMode>,
userns_mode: Option<String>,
startup_timeout: Option<Duration>,
}

/// Represents a port mapping between a local port and the internal port of a container.
Expand Down Expand Up @@ -124,6 +125,11 @@
) -> Result<Vec<ExecCommand>, TestcontainersError> {
self.image.exec_after_start(cs)
}

/// Returns the startup timeout for the container.
pub fn startup_timeout(&self) -> Option<Duration> {
self.startup_timeout
}
}

impl<I: Image> RunnableImage<I> {
Expand Down Expand Up @@ -223,7 +229,7 @@
/// cgroup namespace mode for the container. Possible values are:
/// - `\"private\"`: the container runs in its own private cgroup namespace
/// - `\"host\"`: use the host system's cgroup namespace
/// If not specified, the daemon default is used, which can either be `\"private\"` or `\"host\"`, depending on daemon version, kernel support and configuration.

Check warning on line 232 in testcontainers/src/core/image/runnable_image.rs

View workflow job for this annotation

GitHub Actions / clippy

doc list item missing indentation

warning: doc list item missing indentation --> testcontainers/src/core/image/runnable_image.rs:232:9 | 232 | /// If not specified, the daemon default is used, which can either be `\"private\"` or `\"host\"`, depending on daemon version, kerne... | ^ | = help: if this is supposed to be its own paragraph, add a blank line = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation = note: `#[warn(clippy::doc_lazy_continuation)]` on by default help: indent this line | 232 | /// If not specified, the daemon default is used, which can either be `\"private\"` or `\"host\"`, depending on daemon version, kernel support and configuration. | ++
pub fn with_cgroupns_mode(self, cgroupns_mode: CgroupnsMode) -> Self {
Self {
cgroupns_mode: Some(cgroupns_mode),
Expand All @@ -246,6 +252,14 @@
..self
}
}

/// Sets the startup timeout for the container. The default is 60 seconds.
pub fn with_startup_timeout(self, timeout: Duration) -> Self {
Self {
startup_timeout: Some(timeout),
..self
}
}
}

impl<I> From<I> for RunnableImage<I>
Expand Down Expand Up @@ -275,6 +289,7 @@
shm_size: None,
cgroupns_mode: None,
userns_mode: None,
startup_timeout: None,
}
}
}
Expand Down
Loading
Loading