@@ -359,7 +359,8 @@ impl Pool {
359359 . connection_idle_duration
360360 . lock ( )
361361 . unwrap ( )
362- . saturating_record ( since. elapsed ( ) . as_micros ( ) as u64 ) ;
362+ . record ( since. elapsed ( ) . as_micros ( ) as u64 )
363+ . ok ( ) ;
363364 #[ cfg( feature = "hdrhistogram" ) ]
364365 let metrics = self . metrics ( ) ;
365366 conn. inner . active_since = Instant :: now ( ) ;
@@ -371,9 +372,8 @@ impl Pool {
371372 . check_duration
372373 . lock ( )
373374 . unwrap ( )
374- . saturating_record (
375- conn. inner . active_since . elapsed ( ) . as_micros ( ) as u64
376- ) ;
375+ . record ( conn. inner . active_since . elapsed ( ) . as_micros ( ) as u64 )
376+ . ok ( ) ;
377377 Ok ( conn)
378378 }
379379 . boxed ( ) ,
@@ -412,9 +412,8 @@ impl Pool {
412412 . connect_duration
413413 . lock ( )
414414 . unwrap ( )
415- . saturating_record (
416- conn. inner . active_since . elapsed ( ) . as_micros ( ) as u64
417- ) ;
415+ . record ( conn. inner . active_since . elapsed ( ) . as_micros ( ) as u64 )
416+ . ok ( ) ;
418417 }
419418 conn
420419 }
@@ -1244,6 +1243,24 @@ mod test {
12441243 Ok ( ( ) )
12451244 }
12461245
1246+ #[ cfg( feature = "hdrhistogram" ) ]
1247+ #[ tokio:: test]
1248+ async fn metrics ( ) -> super :: Result < ( ) > {
1249+ let pool = pool_with_one_connection ( ) ;
1250+
1251+ let metrics = pool. metrics ( ) ;
1252+ let conn = pool. get_conn ( ) . await . unwrap ( ) ;
1253+ tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
1254+ drop ( conn) ;
1255+ pool. get_conn ( ) . await . unwrap ( ) ;
1256+
1257+ let max = metrics. connection_active_duration . lock ( ) . unwrap ( ) . max ( ) ;
1258+ // We slept for 100 miliseconds holding a conneciton.
1259+ assert ! ( max > 100_000 ) ;
1260+
1261+ Ok ( ( ) )
1262+ }
1263+
12471264 #[ cfg( feature = "nightly" ) ]
12481265 mod bench {
12491266 use futures_util:: future:: { FutureExt , TryFutureExt } ;
0 commit comments