Skip to content

Commit 24a3c23

Browse files
authored
Fix parsing of float ms (#949)
1 parent 50fc882 commit 24a3c23

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

core/src/worker/nexus.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,34 @@ fn parse_request_timeout(timeout: &str) -> Result<Duration, anyhow::Error> {
404404
.map(Duration::from_secs_f64)
405405
.map_err(Into::into),
406406
"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)),
410410
_ => Err(anyhow!("Invalid timeout format")),
411411
}
412412
}
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+
}

0 commit comments

Comments
 (0)