diff --git a/src/tools/remote-test-client/src/main.rs b/src/tools/remote-test-client/src/main.rs index b9741431b5034..21043f0994574 100644 --- a/src/tools/remote-test-client/src/main.rs +++ b/src/tools/remote-test-client/src/main.rs @@ -11,12 +11,16 @@ 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 { ($e:expr) => { match $e { @@ -56,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()); @@ -69,7 +84,10 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option