Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/conn/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,43 @@ mod test {
Ok(())
}

#[tokio::test]
async fn fifo() {
// This documents a bug causing connections to not served in a
// FIFO order.

let waker = Waker::noop();
let mut context = Context::from_waker(waker);
let pool = pool_with_one_connection();

// Get a connection, so we know the next future will be
// queued.
let conn = pool.get_conn().await.unwrap();

// Try getting a second connection and check that the future
// is pending.
let mut fut2 = pin!(pool.get_conn());
let p = fut2.as_mut().poll(&mut context);
assert!(matches!(p, Poll::Pending));

let queue_len = || pool.inner.exchange.lock().unwrap().waiting.queue.len();
// The second future is now queued
assert_eq!(1, queue_len());

// Drop the first connection and wait for the queue to clear.
drop(conn);
while queue_len() != 0 {
tokio::time::sleep(Duration::from_millis(100)).await;
}

// Create a third future waiting for a connection.
let mut fut3 = pin!(pool.get_conn());

// If the runtime polls fut3 now it is resolved before fut2.
let p = fut3.as_mut().poll(&mut context);
assert!(matches!(p, Poll::Ready(_)));
}

#[tokio::test]
async fn save_last_waker() {
// Test that if passed multiple wakers, we call the last one.
Expand Down
Loading