File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -404,9 +404,34 @@ fn parse_request_timeout(timeout: &str) -> Result<Duration, anyhow::Error> {
404
404
. map ( Duration :: from_secs_f64)
405
405
. map_err ( Into :: into) ,
406
406
"ms" => value
407
- . parse :: < u64 > ( )
408
- . map ( Duration :: from_millis )
409
- . map_err ( Into :: into) ,
407
+ . parse :: < f64 > ( )
408
+ . map_err ( anyhow :: Error :: from )
409
+ . and_then ( |v| Duration :: try_from_secs_f64 ( v / 1000.0 ) . map_err ( Into :: into) ) ,
410
410
_ => Err ( anyhow ! ( "Invalid timeout format" ) ) ,
411
411
}
412
412
}
413
+
414
+ #[ cfg( test) ]
415
+ mod tests {
416
+ use super :: * ;
417
+
418
+ #[ tokio:: test]
419
+ async fn test_parse_request_timeout ( ) {
420
+ assert_eq ! (
421
+ parse_request_timeout( "10m" ) . unwrap( ) ,
422
+ Duration :: from_secs( 600 )
423
+ ) ;
424
+ assert_eq ! (
425
+ parse_request_timeout( "30s" ) . unwrap( ) ,
426
+ Duration :: from_secs( 30 )
427
+ ) ;
428
+ assert_eq ! (
429
+ parse_request_timeout( "500ms" ) . unwrap( ) ,
430
+ Duration :: from_millis( 500 )
431
+ ) ;
432
+ assert_eq ! (
433
+ parse_request_timeout( "9.155416ms" ) . unwrap( ) ,
434
+ Duration :: from_secs_f64( 9.155416 / 1000.0 )
435
+ ) ;
436
+ }
437
+ }
You can’t perform that action at this time.
0 commit comments