Skip to content

Commit

Permalink
shotover#1650 Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justinweng-instaclustr committed Jun 11, 2024
1 parent e5e696f commit 242c496
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
52 changes: 52 additions & 0 deletions shotover-proxy/tests/redis_int_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::thread::sleep;
use std::time::Duration;
use test_helpers::connection::redis_connection;
use test_helpers::docker_compose::docker_compose;
use test_helpers::metrics::assert_metrics_key_value;
use test_helpers::shotover_process::{Count, EventMatcher, Level};

pub mod assert;
Expand Down Expand Up @@ -321,3 +322,54 @@ async fn cluster_dr() {

shotover.shutdown_and_then_consume_events(&[]).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_failed_requests_metric_sink_single() {
let _compose = docker_compose("tests/test-configs/redis/passthrough/docker-compose.yaml");
let shotover = shotover_process("tests/test-configs/redis/passthrough/topology.yaml")
.start()
.await;
let mut connection = redis_connection::new_async("127.0.0.1", 6379).await;

redis::cmd("INVALID_COMMAND")
.arg("foo")
.query_async::<_, ()>(&mut connection)
.await
.unwrap_err();

// Redis client driver initialization sends 2 CLIENT SETINFO commands which trigger 2 errors
// because those commands are not available in the currently used redis version.
assert_metrics_key_value(
r#"shotover_failed_requests_count{chain="redis",transform="RedisSinkSingle"}"#,
"3",
)
.await;

shotover.shutdown_and_then_consume_events(&[]).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_failed_requests_metric_sink_cluster() {
let _compose = docker_compose("tests/test-configs/redis/cluster-handling/docker-compose.yaml");
let shotover = shotover_process("tests/test-configs/redis/cluster-handling/topology.yaml")
.start()
.await;

let mut connection = redis_connection::new_async("127.0.0.1", 6379).await;

redis::cmd("INVALID_COMMAND")
.arg("foo")
.query_async::<_, ()>(&mut connection)
.await
.unwrap_err();

// Redis client driver initialization sends 2 CLIENT SETINFO commands which trigger 2 errors
// because those commands are not available in the currently used redis version.
assert_metrics_key_value(
r#"shotover_failed_requests_count{chain="redis",transform="RedisSinkCluster"}"#,
"3",
)
.await;

shotover.shutdown_and_then_consume_events(&[]).await;
}
5 changes: 1 addition & 4 deletions shotover/src/transforms/redis/sink_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,13 @@ impl RedisSinkClusterBuilder {
chain_name: String,
shared_topology: Arc<RwLock<Topology>>,
) -> Self {
let failed_requests =
counter!("shotover_failed_requests_count", "chain" => chain_name, "transform" => NAME);

RedisSinkClusterBuilder {
first_contact_points,
direct_destination,
connection_count,
connection_pool,
shared_topology,
failed_requests,
failed_requests: counter!("shotover_failed_requests_count", "chain" => chain_name, "transform" => NAME),
}
}
}
Expand Down

0 comments on commit 242c496

Please sign in to comment.