Skip to content

Commit

Permalink
Move connection helpers into test_helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Dec 19, 2022
1 parent ab7aaba commit 1adb68f
Show file tree
Hide file tree
Showing 34 changed files with 129 additions and 106 deletions.
30 changes: 20 additions & 10 deletions Cargo.lock

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

8 changes: 3 additions & 5 deletions shotover-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "Apache-2.0"
[features]
# Include WIP alpha transforms in the public API
alpha-transforms = []
cassandra-cpp-driver-tests = []
cassandra-cpp-driver-tests = ["test-helpers/cassandra-cpp-driver-tests"]

[dependencies]
pretty-hex = "0.3.0"
Expand Down Expand Up @@ -84,16 +84,14 @@ redis = { version = "0.22.0", features = ["tokio-comp", "cluster"] }
pcap = "1.0.0"
pktparse = { version = "0.7.0", features = ["serde"] }
tls-parser = "0.11.0"
tokio-io-timeout = "1.1.1"
serial_test = "0.9.0"
cassandra-cpp = "1.2.0"
test-helpers = { path = "../test-helpers" }
cassandra-cpp = { version = "1.2.0" }
test-helpers = { path = "../test-helpers", features = ["cassandra-cpp-driver-tests"] }
hex-literal = "0.3.3"
nix = "0.26.0"
reqwest = "0.11.6"
metrics-util = "0.14.0"
cdrs-tokio = { git = "https://github.com/krojew/cdrs-tokio", branch = "8.0-dev" }
scylla = { git = "https://github.com/scylladb/scylla-rust-driver", features = ["ssl"] }
rstest = "0.16.0"

[[bench]]
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/benches/benches/cassandra.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::helpers::cassandra::{CassandraConnection, CassandraDriver};
use crate::helpers::ShotoverManager;
use cassandra_cpp::{stmt, Session, Statement};
use criterion::{criterion_group, criterion_main, Criterion};
use std::collections::HashMap;
use test_helpers::cert::generate_cassandra_test_certs;
use test_helpers::connection::cassandra::{CassandraConnection, CassandraDriver};
use test_helpers::docker_compose::DockerCompose;
use test_helpers::lazy::new_lazy_shared;

Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/benches/benches/redis.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use criterion::{criterion_group, Criterion};
use redis::Cmd;
use std::path::Path;
use test_helpers::connection::redis_connection;
use test_helpers::docker_compose::DockerCompose;
use test_helpers::lazy::new_lazy_shared;

use crate::helpers::redis_connection;
use crate::helpers::ShotoverManager;

struct Query {
Expand Down
4 changes: 3 additions & 1 deletion shotover-proxy/tests/cassandra_int_tests/batch_statements.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::helpers::cassandra::{assert_query_result, run_query, CassandraConnection, ResultValue};
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, ResultValue,
};

async fn use_statement(connection: &CassandraConnection) {
{
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/tests/cassandra_int_tests/cache/assert.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helpers::cassandra::{assert_query_result, CassandraConnection, ResultValue};
use metrics_util::debugging::{DebugValue, Snapshotter};
use redis::Commands;
use std::collections::HashSet;
use test_helpers::connection::cassandra::{assert_query_result, CassandraConnection, ResultValue};

/// gets the current miss count from the cache instrumentation.
fn get_cache_miss_value(snapshotter: &Snapshotter) -> u64 {
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/tests/cassandra_int_tests/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mod assert;

use crate::helpers::cassandra::{run_query, CassandraConnection, ResultValue};
use metrics_util::debugging::Snapshotter;
use redis::Commands;
use std::collections::HashSet;
use test_helpers::connection::cassandra::{run_query, CassandraConnection, ResultValue};

pub async fn test(
cassandra_session: &CassandraConnection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cassandra_int_tests::cluster::run_topology_task;
use crate::helpers::cassandra::{assert_query_result, CassandraConnection, ResultValue};
use std::net::SocketAddr;
use test_helpers::connection::cassandra::{assert_query_result, CassandraConnection, ResultValue};

async fn test_rewrite_system_peers(connection: &CassandraConnection) {
let star_results = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cassandra_int_tests::cluster::run_topology_task;
use crate::helpers::cassandra::{assert_query_result, CassandraConnection, ResultValue};
use std::net::SocketAddr;
use test_helpers::connection::cassandra::{assert_query_result, CassandraConnection, ResultValue};

async fn test_rewrite_system_peers_dummy_peers(connection: &CassandraConnection) {
let star_results1 = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::cassandra_int_tests::cluster::run_topology_task;
use crate::helpers::cassandra::{
assert_query_result, run_query, CassandraConnection, CassandraDriver, ResultValue,
};
use cassandra_protocol::events::ServerEvent;
use cassandra_protocol::frame::events::{StatusChange, StatusChangeType};
use std::net::SocketAddr;
use std::time::Duration;
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, CassandraDriver, ResultValue,
};
use test_helpers::docker_compose::DockerCompose;
use tokio::sync::broadcast;
use tokio::time::{sleep, timeout};
Expand Down
6 changes: 3 additions & 3 deletions shotover-proxy/tests/cassandra_int_tests/collections.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::helpers::cassandra::{
assert_query_result, run_query, CassandraConnection, CassandraDriver, ResultValue,
};
use cassandra_protocol::frame::message_result::ColType;
use itertools::Itertools;
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, CassandraDriver, ResultValue,
};

const NATIVE_COL_TYPES: [ColType; 18] = [
ColType::Ascii,
Expand Down
4 changes: 3 additions & 1 deletion shotover-proxy/tests/cassandra_int_tests/functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::helpers::cassandra::{assert_query_result, run_query, CassandraConnection, ResultValue};
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, ResultValue,
};

async fn drop_function(session: &CassandraConnection) {
assert_query_result(
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/tests/cassandra_int_tests/keyspace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::helpers::cassandra::{
use test_helpers::connection::cassandra::{
assert_query_result, assert_query_result_contains_row, run_query, CassandraConnection,
ResultValue,
};
Expand Down
14 changes: 7 additions & 7 deletions shotover-proxy/tests/cassandra_int_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
use crate::helpers::cassandra::{assert_query_result, ResultValue};
#[cfg(feature = "cassandra-cpp-driver-tests")]
use crate::helpers::cassandra::{run_query, CassandraDriver::Datastax};
use crate::helpers::cassandra::{
CassandraConnection, CassandraDriver, CassandraDriver::CdrsTokio, CassandraDriver::Scylla,
};
use crate::helpers::redis_connection;
use crate::helpers::ShotoverManager;
#[cfg(feature = "cassandra-cpp-driver-tests")]
use cassandra_protocol::frame::message_error::{ErrorBody, ErrorType};
Expand All @@ -17,6 +10,13 @@ use futures::Future;
use metrics_util::debugging::DebuggingRecorder;
use rstest::rstest;
use serial_test::serial;
use test_helpers::connection::cassandra::{assert_query_result, ResultValue};
#[cfg(feature = "cassandra-cpp-driver-tests")]
use test_helpers::connection::cassandra::{run_query, CassandraDriver::Datastax};
use test_helpers::connection::cassandra::{
CassandraConnection, CassandraDriver, CassandraDriver::CdrsTokio, CassandraDriver::Scylla,
};
use test_helpers::connection::redis_connection;
use test_helpers::docker_compose::DockerCompose;
use tokio::time::{sleep, timeout, Duration};

Expand Down
4 changes: 3 additions & 1 deletion shotover-proxy/tests/cassandra_int_tests/native_types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::helpers::cassandra::{assert_query_result, run_query, CassandraConnection, ResultValue};
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, ResultValue,
};

async fn select(session: &CassandraConnection) {
assert_query_result(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::helpers::cassandra::{assert_query_result, run_query, CassandraConnection, ResultValue};
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, ResultValue,
};

fn values() -> Vec<ResultValue> {
vec![
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helpers::cassandra::{
use futures::Future;
use test_helpers::connection::cassandra::{
assert_query_result, assert_rows, run_query, CassandraConnection, ResultValue,
};
use futures::Future;

async fn delete(session: &CassandraConnection) {
let prepared = session
Expand Down
4 changes: 3 additions & 1 deletion shotover-proxy/tests/cassandra_int_tests/protect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::helpers::cassandra::{assert_query_result, run_query, CassandraConnection, ResultValue};
use chacha20poly1305::Nonce;
use serde::Deserialize;
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, ResultValue,
};

#[derive(Deserialize)]
pub struct Protected {
Expand Down
8 changes: 4 additions & 4 deletions shotover-proxy/tests/cassandra_int_tests/routing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helpers::cassandra::{CassandraConnection, CassandraDriver};
use test_helpers::connection::cassandra::{CassandraConnection, CassandraDriver};

mod single_key {
use crate::helpers::cassandra::{run_query, CassandraConnection, ResultValue};
use test_helpers::connection::cassandra::{run_query, CassandraConnection, ResultValue};

pub async fn create_keyspace(connection: &CassandraConnection) {
let create_ks: &'static str = "CREATE KEYSPACE IF NOT EXISTS test_routing_ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };";
Expand Down Expand Up @@ -75,7 +75,7 @@ mod single_key {
}

mod compound_key {
use crate::helpers::cassandra::{run_query, CassandraConnection, ResultValue};
use test_helpers::connection::cassandra::{run_query, CassandraConnection, ResultValue};

async fn create_keyspace(connection: &CassandraConnection) {
let create_ks: &'static str = "CREATE KEYSPACE IF NOT EXISTS test_routing_ks WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };";
Expand Down Expand Up @@ -183,8 +183,8 @@ mod compound_key {
}

mod composite_key {
use crate::helpers::cassandra::{run_query, CassandraConnection, ResultValue};
use rand::{distributions::Alphanumeric, Rng};
use test_helpers::connection::cassandra::{run_query, CassandraConnection, ResultValue};

pub async fn test(shotover: &CassandraConnection, cassandra: &CassandraConnection) {
simple_test(shotover, cassandra).await;
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/tests/cassandra_int_tests/table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::helpers::cassandra::{
use test_helpers::connection::cassandra::{
assert_query_result, assert_query_result_contains_row, assert_query_result_not_contains_row,
run_query, CassandraConnection, ResultValue,
};
Expand Down
4 changes: 3 additions & 1 deletion shotover-proxy/tests/cassandra_int_tests/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::helpers::cassandra::{assert_query_result, run_query, CassandraConnection, ResultValue};
use std::time::{SystemTime, UNIX_EPOCH};
use test_helpers::connection::cassandra::{
assert_query_result, run_query, CassandraConnection, ResultValue,
};

async fn flag(connection: &CassandraConnection) {
let timestamp = get_timestamp();
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/tests/cassandra_int_tests/udt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::helpers::cassandra::{run_query, CassandraConnection};
use test_helpers::connection::cassandra::{run_query, CassandraConnection};

async fn test_create_udt(session: &CassandraConnection) {
run_query(
Expand Down
4 changes: 2 additions & 2 deletions shotover-proxy/tests/examples/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![cfg(feature = "cassandra-cpp-driver-tests")]
use crate::helpers::cassandra::{
use serial_test::serial;
use test_helpers::connection::cassandra::{
assert_query_result, CassandraConnection, CassandraDriver, ResultValue,
};
use serial_test::serial;
use test_helpers::docker_compose::DockerCompose;

#[tokio::test(flavor = "multi_thread")]
Expand Down
3 changes: 0 additions & 3 deletions shotover-proxy/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use tokio::runtime::{Handle as RuntimeHandle, Runtime};
use tokio::sync::watch;
use tokio::task::JoinHandle;

pub mod cassandra;
pub mod redis_connection;

#[must_use]
pub struct ShotoverManager {
pub runtime: Option<Runtime>,
Expand Down
2 changes: 1 addition & 1 deletion shotover-proxy/tests/redis_int_tests/basic_driver_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::helpers::redis_connection;
use crate::redis_int_tests::assert::*;
use futures::StreamExt;
use rand::{thread_rng, Rng};
Expand All @@ -10,6 +9,7 @@ use shotover_proxy::tcp;
use std::collections::{HashMap, HashSet};
use std::thread::sleep;
use std::time::Duration;
use test_helpers::connection::redis_connection;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

use tokio::time::timeout;
Expand Down
Loading

0 comments on commit 1adb68f

Please sign in to comment.