chore (backend-rs): more connection checks

This commit is contained in:
naskya 2024-06-10 18:09:05 +09:00
parent dd54924a0a
commit 581668c306
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
2 changed files with 60 additions and 6 deletions

View file

@ -41,8 +41,35 @@ mod unit_test {
use super::get_conn;
#[tokio::test]
async fn connect() {
assert!(get_conn().await.is_ok());
assert!(get_conn().await.is_ok());
async fn connect_sequential() {
get_conn().await.unwrap();
get_conn().await.unwrap();
get_conn().await.unwrap();
get_conn().await.unwrap();
get_conn().await.unwrap();
}
#[tokio::test]
async fn connect_concurrent() {
let [c1, c2, c3, c4, c5] = [
get_conn(),
get_conn(),
get_conn(),
get_conn(),
get_conn(),
];
let _ = tokio::try_join!(c1, c2, c3, c4, c5).unwrap();
}
#[tokio::test]
async fn connect_spawn() {
let mut tasks = Vec::new();
for _ in 0..5 {
tasks.push(tokio::spawn(get_conn()));
}
for task in tasks {
task.await.unwrap().unwrap();
}
}
}

View file

@ -119,9 +119,36 @@ mod unit_test {
use redis::AsyncCommands;
#[tokio::test]
async fn connect() {
assert!(get_conn().await.is_ok());
assert!(get_conn().await.is_ok());
async fn connect_sequential() {
get_conn().await.unwrap();
get_conn().await.unwrap();
get_conn().await.unwrap();
get_conn().await.unwrap();
get_conn().await.unwrap();
}
#[tokio::test]
async fn connect_concurrent() {
let [c1, c2, c3, c4, c5] = [
get_conn(),
get_conn(),
get_conn(),
get_conn(),
get_conn(),
];
let _ = tokio::try_join!(c1, c2, c3, c4, c5).unwrap();
}
#[tokio::test]
async fn connect_spawn() {
let mut tasks = Vec::new();
for _ in 0..5 {
tasks.push(tokio::spawn(get_conn()));
}
for task in tasks {
task.await.unwrap().unwrap();
}
}
#[tokio::test]