Skip to content

Commit

Permalink
test(reqpool): add case for multiple redis pools
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Jan 15, 2025
1 parent 65c5d7e commit bbb61ce
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions reqpool/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,51 @@ mod tests {
let actual: RedisResult<String> = conn.get(&key);
assert!(actual.is_err());
}

#[test]
fn test_mock_multiple_redis_pool() {
let mut pool1 = Pool::open(RedisPoolConfig {
redis_ttl: 111,
redis_url: "redis://localhost:6379".to_string(),
})
.unwrap();
let mut pool2 = Pool::open(RedisPoolConfig {
redis_ttl: 111,
redis_url: "redis://localhost:6380".to_string(),
})
.unwrap();

let mut conn1 = pool1.conn().expect("mock conn");
let mut conn2 = pool2.conn().expect("mock conn");

let key = "hello".to_string();
let world = "world".to_string();

{
conn1
.set_ex(key.clone(), world.clone(), 111)
.expect("mock set_ex");
let actual: RedisResult<String> = conn1.get(&key);
assert_eq!(actual, Ok(world.clone()));
}

{
let actual: RedisResult<String> = conn2.get(&key);
assert!(actual.is_err());
}

{
let meme = "meme".to_string();
conn2
.set_ex(key.clone(), meme.clone(), 111)
.expect("mock set_ex");
let actual: RedisResult<String> = conn2.get(&key);
assert_eq!(actual, Ok(meme));
}

{
let actual: RedisResult<String> = conn1.get(&key);
assert_eq!(actual, Ok(world));
}
}
}

0 comments on commit bbb61ce

Please sign in to comment.