@@ -1003,6 +1003,43 @@ mod test {
10031003 Ok ( ( ) )
10041004 }
10051005
1006+ #[ tokio:: test]
1007+ async fn fifo ( ) {
1008+ // This documents a bug causing connections to not served in a
1009+ // FIFO order.
1010+
1011+ let waker = Waker :: noop ( ) ;
1012+ let mut context = Context :: from_waker ( waker) ;
1013+ let pool = pool_with_one_connection ( ) ;
1014+
1015+ // Get a connection, so we know the next future will be
1016+ // queued.
1017+ let conn = pool. get_conn ( ) . await . unwrap ( ) ;
1018+
1019+ // Try getting a second connection and check that the future
1020+ // is pending.
1021+ let mut fut2 = pin ! ( pool. get_conn( ) ) ;
1022+ let p = fut2. as_mut ( ) . poll ( & mut context) ;
1023+ assert ! ( matches!( p, Poll :: Pending ) ) ;
1024+
1025+ let queue_len = || pool. inner . exchange . lock ( ) . unwrap ( ) . waiting . queue . len ( ) ;
1026+ // The second future is now queued
1027+ assert_eq ! ( 1 , queue_len( ) ) ;
1028+
1029+ // Drop the first connection and wait for the queue to clear.
1030+ drop ( conn) ;
1031+ while queue_len ( ) != 0 {
1032+ tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
1033+ }
1034+
1035+ // Create a third future waiting for a connection.
1036+ let mut fut3 = pin ! ( pool. get_conn( ) ) ;
1037+
1038+ // If the runtime polls fut3 now it is resolved before fut2.
1039+ let p = fut3. as_mut ( ) . poll ( & mut context) ;
1040+ assert ! ( matches!( p, Poll :: Ready ( _) ) ) ;
1041+ }
1042+
10061043 #[ tokio:: test]
10071044 async fn save_last_waker ( ) {
10081045 // Test that if passed multiple wakers, we call the last one.
0 commit comments