Skip to content

Commit

Permalink
Add tests for deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
levkk authored and djc committed Jan 26, 2024
1 parent d4fa529 commit d23b7e3
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bb8/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,55 @@ async fn test_get_timeout() {
ready(r).await.unwrap();
}

#[tokio::test]
async fn test_lots_of_waiters() {
let pool = Pool::builder()
.max_size(3)
.connection_timeout(Duration::from_millis(5_000))
.build(OkManager::<FakeConnection>::new())
.await
.unwrap();

let mut waiters: Vec<oneshot::Receiver<()>> = Vec::new();

for _ in 0..25000 {
let pool = pool.clone();
let (tx, rx) = oneshot::channel();
waiters.push(rx);
tokio::spawn(async move {
let _conn = pool.get().await.unwrap();
tx.send(()).unwrap();
});
}

let results = futures_util::future::join_all(&mut waiters).await;

for result in results {
assert!(result.is_ok());
}
}

#[tokio::test]
async fn test_timeout_caller() {
let pool = Pool::builder()
.max_size(1)
.connection_timeout(Duration::from_millis(5_000))
.build(OkManager::<FakeConnection>::new())
.await
.unwrap();

let one = pool.get().await;
assert!(one.is_ok());

let res = tokio::time::timeout(Duration::from_millis(100), pool.get()).await;
assert!(res.is_err());

drop(one);

let two = pool.get().await;
assert!(two.is_ok());
}

#[tokio::test]
async fn test_now_invalid() {
static INVALID: AtomicBool = AtomicBool::new(false);
Expand Down

0 comments on commit d23b7e3

Please sign in to comment.