diff --git a/sentry/src/db.rs b/sentry/src/db.rs index dc7d62a5d..9b64fcac3 100644 --- a/sentry/src/db.rs +++ b/sentry/src/db.rs @@ -29,7 +29,7 @@ pub use tokio_postgres::Config as PostgresConfig; // Re-export the Postgres PoolError for easier usages pub use deadpool_postgres::PoolError; // Re-export the redis RedisError for easier usage -pub use redis::{RedisError, cmd as redis_cmd}; +pub use redis::RedisError; pub type DbPool = deadpool_postgres::Pool; @@ -138,7 +138,7 @@ pub async fn setup_migrations(environment: Environment) { .expect("Reloading config for migration failed"); } -#[cfg(any(test, feature = "test-util"))] +#[cfg(feature = "test-util")] pub mod tests_postgres { use std::{ ops::{Deref, DerefMut}, @@ -428,7 +428,7 @@ pub mod tests_postgres { } } -#[cfg(test)] +#[cfg(feature = "test-util")] pub mod redis_pool { use dashmap::DashMap; @@ -442,6 +442,9 @@ pub mod redis_pool { use super::*; + /// Re-export [`redis::cmd`] for testing purposes + pub use redis::cmd; + pub type Pool = deadpool::managed::Pool; pub static TESTS_POOL: Lazy = diff --git a/test_harness/src/lib.rs b/test_harness/src/lib.rs index 9a9d27430..af12e22ec 100644 --- a/test_harness/src/lib.rs +++ b/test_harness/src/lib.rs @@ -696,8 +696,8 @@ pub mod run { use sentry::{ application::{logger, run}, db::{ - postgres_connection, redis_connection, tests_postgres::setup_test_migrations, - CampaignRemaining, + postgres_connection, redis_connection, redis_pool::Manager, + tests_postgres::setup_test_migrations, CampaignRemaining, }, Application, }; @@ -729,9 +729,9 @@ pub mod run { let postgres = postgres_connection(42, postgres_config).await; let mut redis = redis_connection(app_config.redis_url).await?; - sentry::db::redis_cmd("FLUSHDB") - .query_async::<_, String>(&mut redis) - .await.unwrap(); + + Manager::flush_db(&mut redis).await.expect("Should flush redis database"); + let campaign_remaining = CampaignRemaining::new(redis.clone()); setup_test_migrations(postgres.clone())