Skip to content

Commit

Permalink
verifying that the connection object itself is being reused
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrfoss committed Aug 5, 2024
1 parent 628f027 commit f250230
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions redis/tests/redis_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use deadpool_redis::cluster::Runtime;
use futures::FutureExt;
use redis::cmd;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tokio::sync::Mutex;

#[derive(Debug, Default, Deserialize, Serialize)]
struct Config {
Expand Down Expand Up @@ -94,26 +96,40 @@ async fn test_aborted_command() {
async fn test_recycled() {
let pool = create_pool();

let connection_reused = Arc::new(Mutex::new(false));

let client_id_1 = {
let mut conn = pool.get().await.unwrap();
cmd("CLIENT")
let client_id: i64 = cmd("CLIENT")
.arg("ID")
.query_async::<i64>(&mut conn)
.query_async(&mut conn)
.await
.unwrap()
.unwrap();

let mut reused = connection_reused.lock().await;
*reused = true;

client_id
};

drop(client_id_1);

let client_id_2 = {
let mut conn = pool.get().await.unwrap();
cmd("CLIENT")
let client_id: i64 = cmd("CLIENT")
.arg("ID")
.query_async::<i64>(&mut conn)
.query_async(&mut conn)
.await
.unwrap()
.unwrap();

let reused = connection_reused.lock().await;
assert!(*reused, "Connection was not reused");

client_id
};

assert_eq!(
client_id_1, client_id_2,
"the redis connection was not recycled"
"The Redis connection was not recycled"
);
}

0 comments on commit f250230

Please sign in to comment.