feat: add option to stop containers with a timeout#779
Merged
DDtKey merged 2 commits intotestcontainers:mainfrom May 4, 2025
Merged
feat: add option to stop containers with a timeout#779DDtKey merged 2 commits intotestcontainers:mainfrom
DDtKey merged 2 commits intotestcontainers:mainfrom
Conversation
✅ Deploy Preview for testcontainers-rust ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
96e10b5 to
3d210d5
Compare
Contributor
|
Thank you for the contribution! 👍 I've fixed PR name |
b532967 to
e1d188d
Compare
Contributor
Author
|
Apologies for that, not sure what happened with the linter and forgot to enable all features! |
DDtKey
approved these changes
Mar 25, 2025
54bf1fc to
e337458
Compare
8479c44 to
887bcae
Compare
Contributor
Author
|
I think this is now there! there is a new clippy lint I dont think I want to get into: I also want to test this on my problematic container just to make sure |
Previously containers were stopped with the system default timeout before issuing SIGKILL which was interfering with clean shutdown of processes being tested. This commit adds a new API of stop_with_timeout(Option<timeout_seconds>) in addition to the original stop() which retains its original functionality. A value of Some(-1) will issue a SIGTERM then wait indefinitely, a value of Some(t) will issue a SIGTERM then wait t seconds before issuing a SIGKILL. A value of None will follow the system default - often waiting 10 seconds, but this is configurable within the docker engine.
fb908c1 to
5c63b12
Compare
DDtKey
approved these changes
Apr 29, 2025
Contributor
DDtKey
left a comment
There was a problem hiding this comment.
Thank you for the contribution!
Really appreciate it!
Sorry for the delay, we probably should have fix the lints in separate PR before.
But I don't mind merging as part of this PR
DDtKey
approved these changes
May 4, 2025
Merged
DDtKey
pushed a commit
that referenced
this pull request
May 4, 2025
## 🤖 New release
* `testcontainers`: 0.23.3 -> 0.24.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.40.0/src/lints/enum_variant_added.ron
Failed in:
variant CmdWaitFor:Exit in /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/wait/cmd_wait.rs:16
variant ClientError:PauseContainer in /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/client.rs:81
variant ClientError:UnpauseContainer in /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/client.rs:83
variant ClientError:PauseContainer in /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/client.rs:81
variant ClientError:UnpauseContainer in /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/client.rs:83
--- failure enum_variant_missing: pub enum variant removed or renamed ---
Description:
A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.40.0/src/lints/enum_variant_missing.ron
Failed in:
variant CmdWaitFor::ExitCode, previously in file /tmp/.tmp7IxuhL/testcontainers/src/core/wait/cmd_wait.rs:16
--- 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.40.0/src/lints/trait_method_added.ron
Failed in:
trait method testcontainers::core::ImageExt::with_user in file /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:171
trait method testcontainers::core::ImageExt::with_readonly_rootfs in file /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:174
trait method testcontainers::core::ImageExt::with_security_opt in file /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:177
trait method testcontainers::ImageExt::with_user in file /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:171
trait method testcontainers::ImageExt::with_readonly_rootfs in file /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:174
trait method testcontainers::ImageExt::with_security_opt in file /tmp/.tmpPG1hwc/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:177
```
<details><summary><i><b>Changelog</b></i></summary><p>
<blockquote>
## [0.24.0] - 2025-05-04
### Details
#### Features
- Support waiting for commands exit regardless of exit code (#771)
- Add user configuration for container commands (#784)
- Add option to stop containers with a timeout (#779)
- Support `pause` and `unpause` container (#785)
- Allow `security_opt` and `readonly_rootfs` to be configured (#787)
#### Miscellaneous Tasks
- Update etcetera requirement from 0.8.0 to 0.9.0 (#773)
- Update etcetera requirement from 0.9.0 to 0.10.0 (#775)
</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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously containers were stopped with no timeout (SIGKILL) which was interfering with clean shutdown of processes being tested.
This commit adds a new API of stop_with_timeout(timeout_secconds) in addition to the original stop(). The original stop() interface calls stop_with_timeout using the default '0'.
EDIT:
It would seem my original diagnosis was incorrect and the default timeout is 10 seconds, but my CI system was somehow setting the default to 1 second. I will fix the docs and put in the correct default. I think there is still some value in here - apologies for the time waste getting to this point!