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

Move stop_service into DockerCompose #866

Merged
merged 3 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion shotover-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 3 additions & 27 deletions shotover-proxy/tests/cassandra_int_tests/cluster_single_rack_v4.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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<String> = 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
Expand Down
1 change: 1 addition & 0 deletions test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
28 changes: 28 additions & 0 deletions test-helpers/src/docker_compose.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{anyhow, Result};
use docker_api::Docker;
use regex::Regex;
use std::io::ErrorKind;
use std::process::Command;
Expand Down Expand Up @@ -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<String> = 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" => {
Expand Down