Skip to content

Commit

Permalink
Round timeout to nearest second when using ping command
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Aug 28, 2024
1 parent 5efc663 commit ef8cc10
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion test/connection-checker/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,26 @@ pub fn send_ping(opt: &Opt, destination: IpAddr) -> eyre::Result<()> {

let mut cmd = std::process::Command::new("ping");

let timeout_sec = ((opt.leak_timeout as f32) / 1000f32).to_string();
// NOTE: Rounding up to nearest second, since some versions don't support fractional
// seconds
let timeout_sec = ((opt.leak_timeout + 1000 - 1) / 1000).to_string();

cmd.args(["-c", "1", "-W", &timeout_sec, &destination.to_string()]);

let output = cmd.output().wrap_err(eyre!(
"Failed to execute ping for destination {destination}"
))?;

if !output.status.success() {
eprintln!(
"ping stdout:\n\n{}",
std::str::from_utf8(&output.stdout).unwrap_or_else(|| "invalid utf8".to_string())
);
eprintln!(
"ping stderr:\n\n{}",
std::str::from_utf8(&output.stderr).unwrap_or_else(|| "invalid utf8".to_string())
);

return Err(eyre!("ping for destination {destination} failed"));
}

Expand Down

0 comments on commit ef8cc10

Please sign in to comment.