File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -317,6 +317,55 @@ async fn test_get_timeout() {
317
317
ready ( r) . await . unwrap ( ) ;
318
318
}
319
319
320
+ #[ tokio:: test]
321
+ async fn test_lots_of_waiters ( ) {
322
+ let pool = Pool :: builder ( )
323
+ . max_size ( 3 )
324
+ . connection_timeout ( Duration :: from_millis ( 5_000 ) )
325
+ . build ( OkManager :: < FakeConnection > :: new ( ) )
326
+ . await
327
+ . unwrap ( ) ;
328
+
329
+ let mut waiters: Vec < oneshot:: Receiver < ( ) > > = Vec :: new ( ) ;
330
+
331
+ for _ in 0 ..25000 {
332
+ let pool = pool. clone ( ) ;
333
+ let ( tx, rx) = oneshot:: channel ( ) ;
334
+ waiters. push ( rx) ;
335
+ tokio:: spawn ( async move {
336
+ let _conn = pool. get ( ) . await . unwrap ( ) ;
337
+ tx. send ( ( ) ) . unwrap ( ) ;
338
+ } ) ;
339
+ }
340
+
341
+ let results = futures_util:: future:: join_all ( & mut waiters) . await ;
342
+
343
+ for result in results {
344
+ assert ! ( result. is_ok( ) ) ;
345
+ }
346
+ }
347
+
348
+ #[ tokio:: test]
349
+ async fn test_timeout_caller ( ) {
350
+ let pool = Pool :: builder ( )
351
+ . max_size ( 1 )
352
+ . connection_timeout ( Duration :: from_millis ( 5_000 ) )
353
+ . build ( OkManager :: < FakeConnection > :: new ( ) )
354
+ . await
355
+ . unwrap ( ) ;
356
+
357
+ let one = pool. get ( ) . await ;
358
+ assert ! ( one. is_ok( ) ) ;
359
+
360
+ let res = tokio:: time:: timeout ( Duration :: from_millis ( 100 ) , pool. get ( ) ) . await ;
361
+ assert ! ( res. is_err( ) ) ;
362
+
363
+ drop ( one) ;
364
+
365
+ let two = pool. get ( ) . await ;
366
+ assert ! ( two. is_ok( ) ) ;
367
+ }
368
+
320
369
#[ tokio:: test]
321
370
async fn test_now_invalid ( ) {
322
371
static INVALID : AtomicBool = AtomicBool :: new ( false ) ;
You can’t perform that action at this time.
0 commit comments