-
Notifications
You must be signed in to change notification settings - Fork 172
fix: reuse container requires name #887
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,9 +117,19 @@ where | |
|
|
||
| #[cfg(feature = "reusable-containers")] | ||
| { | ||
| use crate::ReuseDirective::{Always, CurrentSession}; | ||
| use crate::{ | ||
| core::env::ConfigurationError, | ||
| ReuseDirective::{Always, CurrentSession}, | ||
| TestcontainersError, | ||
| }; | ||
|
|
||
| if matches!(container_req.reuse(), Always | CurrentSession) { | ||
| if labels.is_empty() && container_req.container_name().is_none() { | ||
| return Err(TestcontainersError::Client(ClientError::Configuration( | ||
| ConfigurationError::MissingContainerNameAndLabels, | ||
| ))); | ||
| } | ||
|
|
||
| if let Some(container_id) = client | ||
| .get_running_container_id( | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, this can't handle the case where an existing container is stopped. It would then failed with: I resolve this issue in my bollard based solution by removing a stopped container with the same name, but not sure how to make it more smoothly in testcontainers. Anyway, this can be a follow-up to improved: async fn maybe_remove_container(&self, docker: &Docker, container_name: &str) {
let options = Some(RemoveContainerOptions {
v: true,
force: true,
link: false,
});
// best effort to remove existing container; ignore errors
let _ = docker.remove_container(container_name, options).await;
}
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is common when a lasting test container gets stopped during the dev machine reboot. |
||
| container_req.container_name().as_deref(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why containers are always removed as reported in #742 (comment)
I'm using sync Containers and its Drop impl isn't properly forwarded to the async impl.