diff --git a/Cargo.lock b/Cargo.lock index 9580b37c9..a69e14338 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3055,7 +3055,6 @@ dependencies = [ "criterion", "csv", "derivative", - "docker-api", "futures", "generic-array", "governor", @@ -3280,6 +3279,7 @@ name = "test-helpers" version = "0.1.0" dependencies = [ "anyhow", + "docker-api", "nix", "rcgen", "regex", diff --git a/shotover-proxy/Cargo.toml b/shotover-proxy/Cargo.toml index b91b63ef3..9f8de11cf 100644 --- a/shotover-proxy/Cargo.toml +++ b/shotover-proxy/Cargo.toml @@ -93,7 +93,6 @@ metrics-util = "0.14.0" cdrs-tokio = { git = "https://github.com/krojew/cdrs-tokio", branch = "8.0-dev" } scylla = { version = "0.6.0", features = ["ssl"] } rstest = "0.15.0" -docker-api = "0.11.0" [[bench]] name = "benches" diff --git a/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs b/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs index 2d306b3be..934684d2a 100644 --- a/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs +++ b/shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs @@ -1,6 +1,5 @@ use cassandra_protocol::events::ServerEvent; use cassandra_protocol::frame::events::{StatusChange, StatusChangeType}; -use docker_api::Docker; use test_helpers::docker_compose::DockerCompose; use tokio::time::{sleep, timeout}; @@ -281,32 +280,9 @@ pub async fn test_node_going_down( // let the driver finish connecting to the cluster and registering for the events sleep(Duration::from_secs(10)).await; - // stop one of the containers to trigger a status change event - let docker = Docker::new("unix:///var/run/docker.sock").unwrap(); - let containers = docker.containers(); - let mut found = false; - let mut all_names: Vec = vec![]; - for container in containers.list(&Default::default()).await.unwrap() { - let compose_service = container - .labels - .unwrap() - .get("com.docker.compose.service") - .unwrap() - .to_string(); - // event_connection_direct is connecting to cassandra-one. - // So make sure to instead kill caassandra-two. - if compose_service == "cassandra-two" { - found = true; - let container = containers.get(container.id.unwrap()); - container.stop(None).await.unwrap(); - } - all_names.push(compose_service); - } - assert!( - found, - "container was not found with expected docker compose service name, actual names were {:?}", - all_names - ); + // stop one of the containers to trigger a status change event. + // event_connection_direct is connecting to cassandra-one, so make sure to instead kill caassandra-two. + compose.stop_service("cassandra-two").await; loop { // The direct connection should allow all events to pass through diff --git a/test-helpers/Cargo.toml b/test-helpers/Cargo.toml index 7713bf458..471dc02e7 100644 --- a/test-helpers/Cargo.toml +++ b/test-helpers/Cargo.toml @@ -14,3 +14,4 @@ anyhow = "1.0.42" regex = "1.5.5" nix = "0.25.0" rcgen = "0.10.0" +docker-api = "0.11.0" diff --git a/test-helpers/src/docker_compose.rs b/test-helpers/src/docker_compose.rs index c930ea29c..1f964267c 100644 --- a/test-helpers/src/docker_compose.rs +++ b/test-helpers/src/docker_compose.rs @@ -1,4 +1,5 @@ use anyhow::{anyhow, Result}; +use docker_api::Docker; use regex::Regex; use std::io::ErrorKind; use std::process::Command; @@ -89,6 +90,33 @@ impl DockerCompose { DockerCompose::new("tests/transforms/docker-compose-moto.yml") } + /// Stops the container with the provided service name + pub async fn stop_service(&self, service_name: &str) { + let docker = Docker::new("unix:///var/run/docker.sock").unwrap(); + let containers = docker.containers(); + let mut found = false; + let mut all_names: Vec = vec![]; + for container in containers.list(&Default::default()).await.unwrap() { + let compose_service = container + .labels + .unwrap() + .get("com.docker.compose.service") + .unwrap() + .to_string(); + if compose_service == service_name { + found = true; + let container = containers.get(container.id.unwrap()); + container.stop(None).await.unwrap(); + } + all_names.push(compose_service); + } + assert!( + found, + "container was not found with expected docker compose service name, actual names were {:?}", + all_names + ); + } + fn wait_for_containers_to_startup(&self) { match self.file_path.as_ref() { "tests/transforms/docker-compose-moto.yml" => {