From 799df1c425cbee6bc6747d3e6291f1743dea93db Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 21 Oct 2025 18:05:23 -0500 Subject: [PATCH 1/3] Add a timeout to the `remote-test-client` connection --- src/tools/remote-test-client/src/main.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index b9741431b5034..a35e7c6cd2029 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -15,6 +15,7 @@ use std::time::Duration; use std::{env, thread}; const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR"; +const CONNECT_TIMEOUT: &str = "TEST_DEVICE_CONNECT_TIMEOUT"; const DEFAULT_ADDR: &str = "127.0.0.1:12345"; macro_rules! t { @@ -69,7 +70,22 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option() { + Ok(n) => Some(n), + Err(_) => { + println!("The {CONNECT_TIMEOUT} env variable is not a valid integer, using default timeout"); + None + } + } + }) + .map(Duration::from_secs) + .unwrap_or_else(|| Duration::from_secs(300)); + + while total_dur < timeout { let dur = Duration::from_millis(2000); if let Ok(mut client) = TcpStream::connect(&device_address) { t!(client.set_read_timeout(Some(dur))); @@ -77,12 +93,15 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option Date: Mon, 27 Oct 2025 10:48:56 -0500 Subject: [PATCH 2/3] Address review comments --- src/tools/remote-test-client/src/main.rs | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index a35e7c6cd2029..8ec73373931f9 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -15,9 +15,11 @@ use std::time::Duration; use std::{env, thread}; const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR"; -const CONNECT_TIMEOUT: &str = "TEST_DEVICE_CONNECT_TIMEOUT"; const DEFAULT_ADDR: &str = "127.0.0.1:12345"; +const CONNECT_TIMEOUT_ENV: &str = "TEST_DEVICE_CONNECT_TIMEOUT_SECONDS"; +const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_mins(30); + macro_rules! t { ($e:expr) => { match $e { @@ -71,19 +73,14 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option() { - Ok(n) => Some(n), - Err(_) => { - println!("The {CONNECT_TIMEOUT} env variable is not a valid integer, using default timeout"); - None - } - } - }) - .map(Duration::from_secs) - .unwrap_or_else(|| Duration::from_secs(300)); + let timeout = env::var(CONNECT_TIMEOUT_ENV).ok().map_or(DEFAULT_CONNECT_TIMEOUT, |timeout| { + let seconds = timeout.parse::().unwrap_or_else(|_| { + panic!("The {CONNECT_TIMEOUT_ENV} env variable is not a valid integer"); + }); + Duration::from_secs(seconds) + }); + + let mut timed_out = true; while total_dur < timeout { let dur = Duration::from_millis(2000); @@ -93,7 +90,8 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option Date: Wed, 29 Oct 2025 11:01:37 -0500 Subject: [PATCH 3/3] Address review comments --- src/tools/remote-test-client/src/main.rs | 39 ++++++++++++------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index 8ec73373931f9..21043f0994574 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -11,13 +11,14 @@ use std::io::{self, BufWriter}; use std::net::TcpStream; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::time::Duration; +use std::time::{Duration, Instant}; use std::{env, thread}; const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR"; const DEFAULT_ADDR: &str = "127.0.0.1:12345"; const CONNECT_TIMEOUT_ENV: &str = "TEST_DEVICE_CONNECT_TIMEOUT_SECONDS"; +/// The default timeout is high to not break slow CI or slow device starts. const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_mins(30); macro_rules! t { @@ -59,6 +60,17 @@ fn main() { } } +fn connect_timeout() -> Duration { + match env::var(CONNECT_TIMEOUT_ENV).ok() { + Some(timeout) => timeout.parse().map(Duration::from_secs).unwrap_or_else(|e| { + panic!( + "error: parsing `{CONNECT_TIMEOUT_ENV}` value \"{timeout}\" as seconds failed: {e}" + ) + }), + None => DEFAULT_CONNECT_TIMEOUT, + } +} + fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option) { let device_address = env::var(REMOTE_ADDR_ENV).unwrap_or(DEFAULT_ADDR.to_string()); @@ -72,17 +84,10 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option().unwrap_or_else(|_| { - panic!("The {CONNECT_TIMEOUT_ENV} env variable is not a valid integer"); - }); - Duration::from_secs(seconds) - }); - - let mut timed_out = true; - - while total_dur < timeout { + let timeout = connect_timeout(); + let mut successful_read = false; + let start_time = Instant::now(); + while start_time.elapsed() < timeout { let dur = Duration::from_millis(2000); if let Ok(mut client) = TcpStream::connect(&device_address) { t!(client.set_read_timeout(Some(dur))); @@ -90,20 +95,16 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option