Skip to content

Give remote-test-client a configurable timeout #126959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/tools/remote-test-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ use std::time::Duration;
const REMOTE_ADDR_ENV: &str = "TEST_DEVICE_ADDR";
const DEFAULT_ADDR: &str = "127.0.0.1:12345";

const TCP_TIMEOUT_ENV: &str = "TCP_TIMEOUT";
const DEFAULT_TCP_TIMEOUT: u64 = 100;

macro_rules! t {
($e:expr) => {
match $e {
Expand Down Expand Up @@ -69,16 +72,26 @@ fn spawn_emulator(target: &str, server: &Path, tmpdir: &Path, rootfs: Option<Pat
start_qemu_emulator(target, rootfs, server, tmpdir);
}

let timeout = if let Ok(setting) = env::var(TCP_TIMEOUT_ENV) {
t!(setting.parse())
} else {
DEFAULT_TCP_TIMEOUT
};
let dur = Duration::from_millis(timeout);

// Wait for the emulator to come online
loop {
let dur = Duration::from_millis(100);
if let Ok(mut client) = TcpStream::connect(&device_address) {
t!(client.set_read_timeout(Some(dur)));
t!(client.set_write_timeout(Some(dur)));
if client.write_all(b"ping").is_ok() {
let mut b = [0; 4];
if client.read_exact(&mut b).is_ok() {
break;
match client.read_exact(&mut b) {
Ok(_) => break,
Err(e) if e.kind() == io::ErrorKind::WouldBlock => panic!(
"TCP timeout of {timeout}ms exceeded, set `{TCP_TIMEOUT_ENV}` to a larger value"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a more specific and appropriate error, yes! I wonder why I saw what I did while testing...

),
Err(_) => (),
}
}
}
Expand Down
Loading