Skip to content

Comments

feat: add custom health check support for containers#816

Merged
DDtKey merged 11 commits intotestcontainers:mainfrom
DCjanus:main
Jul 17, 2025
Merged

feat: add custom health check support for containers#816
DDtKey merged 11 commits intotestcontainers:mainfrom
DCjanus:main

Conversation

@DCjanus
Copy link
Contributor

@DCjanus DCjanus commented Jul 16, 2025

Close #814

This commit introduces a new `Healthcheck` struct and related methods to define custom health checks for containers. The health check can be specified when creating a container request, allowing users to override the default health check behavior. Additionally, tests have been added to validate the functionality of the new health check feature.
@netlify
Copy link

netlify bot commented Jul 16, 2025

Deploy Preview for testcontainers-rust ready!

Name Link
🔨 Latest commit e7fcdda
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-rust/deploys/6877895cc32f38000845b12c
😎 Deploy Preview https://deploy-preview-816--testcontainers-rust.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

DCjanus added 10 commits July 16, 2025 15:58
This commit modifies the `Healthcheck` struct methods to accept optional parameters for interval, timeout, retries, start period, and start interval. Passing `None` will clear the values and revert to Docker defaults. Additionally, a new test has been added to verify the functionality of clearing these values.
This commit introduces new tests for custom health checks in both synchronous and asynchronous contexts. The tests validate the application of health checks using shell commands and ensure that the health check configurations are correctly set and functioning as expected. Additionally, the naming of an existing test has been updated for clarity.
This commit removes a series of tests related to the `Healthcheck` struct, including various command and builder pattern tests. The removal is aimed at streamlining the test suite and focusing on more relevant test cases. The functionality of the health check remains intact.
This commit refactors the health check command in both synchronous and asynchronous tests to use the `Healthcheck::cmd` method instead of `cmd_shell`. Additionally, it removes an outdated test case from the asynchronous test suite, streamlining the test code while maintaining functionality.
This commit removes outdated health check test cases from both the asynchronous and synchronous test runners. The removed tests were deemed unnecessary, streamlining the test suite while ensuring that the core functionality of health checks remains intact.
This commit enhances the error handling in healthcheck tests for both asynchronous and synchronous containers by replacing `unwrap()` with `expect()` calls. This change provides clearer error messages when the container configuration or healthcheck configuration is absent, improving the robustness of the test suite.
This commit renames the `inherit` method to `empty` in the `Healthcheck` struct to better reflect its functionality. The updated method description clarifies that it allows customization of an image's existing healthcheck while preserving the original command. This change enhances code readability and understanding.
This commit refactors the import statements in both asynchronous and synchronous container test modules for better organization and clarity. It adds the `HttpWaitStrategy` import in the async tests and includes `ImageExt` in the sync tests, ensuring that all necessary components are clearly defined and improving overall code readability.
This commit reorganizes the import statements in the asynchronous container test module for improved clarity and consistency. The changes enhance code readability by consolidating imports into a single line while maintaining the necessary components for the tests.
Copy link
Contributor

@DDtKey DDtKey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! 👍

Looks good to me

@mervyn-mccreight
Copy link
Contributor

Great work!

@DDtKey DDtKey merged commit 4081b57 into testcontainers:main Jul 17, 2025
12 checks passed
@github-actions github-actions bot mentioned this pull request Jul 17, 2025
@github-actions github-actions bot mentioned this pull request Jul 27, 2025
mervyn-mccreight pushed a commit that referenced this pull request Jul 27, 2025
## 🤖 New release

* `testcontainers`: 0.24.0 -> 0.25.0 (⚠ API breaking changes)

### ⚠ `testcontainers` breaking changes

```text
--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/enum_variant_added.ron

Failed in:
  variant ClientError:BuildImage in /tmp/.tmp8ymZuo/testcontainers-rs/testcontainers/src/core/client.rs:71
  variant ClientError:BuildImage in /tmp/.tmp8ymZuo/testcontainers-rs/testcontainers/src/core/client.rs:71
  variant LogSource:BothStd in /tmp/.tmp8ymZuo/testcontainers-rs/testcontainers/src/core/logs.rs:32

--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/trait_method_added.ron

Failed in:
  trait method testcontainers::core::ImageExt::with_ready_conditions in file /tmp/.tmp8ymZuo/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:184
  trait method testcontainers::core::ImageExt::with_health_check in file /tmp/.tmp8ymZuo/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:206
  trait method testcontainers::ImageExt::with_ready_conditions in file /tmp/.tmp8ymZuo/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:184
  trait method testcontainers::ImageExt::with_health_check in file /tmp/.tmp8ymZuo/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:206
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [0.25.0] - 2025-07-27

### Details
#### Bug Fixes
- Make tls features optional
([#806](#806))
- Add `Send` trait to `stderr` & `stdout` of `ExecResult`
([#809](#809))
- Added new parse rule for correctly parsing ports without protocol
specifier
([#812](#812))

#### Features
- Allow ready conditions customization via ImageExt
([#794](#794))
- Allow to wait for log line on either stdout or stderr
([#795](#795))
- Add `Container*::exit_code`
([#791](#791))
- Add `Container*::is_running`
([#790](#790))
- Add custom health check support for containers
([#816](#816))
- Introduce container builder api
([#801](#801))

#### Miscellaneous Tasks
- [❗] Update bollard to 1.19.1
([#817](#817))

#### Refactor
- Testimages and tests to use builder API
([#804](#804))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature request] Allow overriding the container health check

3 participants