mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-03 20:15:45 +00:00
tests: Wait explicitly for vm shutdown w/ the 'wait-timeout' crate
Instead of waiting blindly with fixed amount of sleeping time, we can use the `wait-timeout` crate to explicitly wait VM shutdown (with a timeout). It can reduces the execution time of some tests substantially. Also, this patch increases the `shutdown` timeout for 'test_reboot', which should fix the recent sporadic failures on this test. Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
cd1c2ed31e
commit
26783fea89
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -234,6 +234,7 @@ dependencies = [
|
|||||||
"vhost_user_net",
|
"vhost_user_net",
|
||||||
"vmm",
|
"vmm",
|
||||||
"vmm-sys-util",
|
"vmm-sys-util",
|
||||||
|
"wait-timeout",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1676,6 +1677,15 @@ dependencies = [
|
|||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wait-timeout"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.9.0+wasi-snapshot-preview1"
|
version = "0.9.0+wasi-snapshot-preview1"
|
||||||
|
@ -28,6 +28,7 @@ vhost_user_block = { path = "vhost_user_block"}
|
|||||||
vhost_user_net = { path = "vhost_user_net"}
|
vhost_user_net = { path = "vhost_user_net"}
|
||||||
vmm = { path = "vmm" }
|
vmm = { path = "vmm" }
|
||||||
vmm-sys-util = "0.6.1"
|
vmm-sys-util = "0.6.1"
|
||||||
|
wait-timeout = "0.2.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
clap = { version = "2.33.3", features = ["wrap_help"] }
|
clap = { version = "2.33.3", features = ["wrap_help"] }
|
||||||
|
@ -31,6 +31,7 @@ mod tests {
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
use wait_timeout::ChildExt;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref NEXT_VM_ID: Mutex<u8> = Mutex::new(1);
|
static ref NEXT_VM_ID: Mutex<u8> = Mutex::new(1);
|
||||||
@ -3513,9 +3514,9 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
guest.ssh_command("sudo shutdown -h now").unwrap();
|
guest.ssh_command("sudo shutdown -h now").unwrap();
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let _ = child.wait_timeout(std::time::Duration::from_secs(20));
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
let output = child.wait_with_output().unwrap();
|
let output = child.wait_with_output().unwrap();
|
||||||
handle_child_output(r, &output);
|
handle_child_output(r, &output);
|
||||||
@ -3607,8 +3608,8 @@ mod tests {
|
|||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
|
||||||
guest.ssh_command("sudo shutdown -h now").unwrap();
|
guest.ssh_command("sudo shutdown -h now").unwrap();
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
|
||||||
|
|
||||||
|
let _ = child.wait_timeout(std::time::Duration::from_secs(20));
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
let output = child.wait_with_output().unwrap();
|
let output = child.wait_with_output().unwrap();
|
||||||
|
|
||||||
@ -3962,9 +3963,9 @@ mod tests {
|
|||||||
guest
|
guest
|
||||||
.ssh_command("sudo shutdown -h now")
|
.ssh_command("sudo shutdown -h now")
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let _ = child.wait_timeout(std::time::Duration::from_secs(40));
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
let output = child.wait_with_output().unwrap();
|
let output = child.wait_with_output().unwrap();
|
||||||
handle_child_output(r, &output);
|
handle_child_output(r, &output);
|
||||||
@ -4026,9 +4027,9 @@ mod tests {
|
|||||||
assert_eq!(fd_count_1, fd_count_2);
|
assert_eq!(fd_count_1, fd_count_2);
|
||||||
|
|
||||||
guest.ssh_command("sudo shutdown -h now").unwrap();
|
guest.ssh_command("sudo shutdown -h now").unwrap();
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let _ = child.wait_timeout(std::time::Duration::from_secs(20));
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
let output = child.wait_with_output().unwrap();
|
let output = child.wait_with_output().unwrap();
|
||||||
handle_child_output(r, &output);
|
handle_child_output(r, &output);
|
||||||
@ -5623,9 +5624,9 @@ mod tests {
|
|||||||
DEFAULT_SSH_TIMEOUT,
|
DEFAULT_SSH_TIMEOUT,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
thread::sleep(std::time::Duration::new(40, 0));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let _ = child.wait_timeout(std::time::Duration::from_secs(40));
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
let output = child.wait_with_output().unwrap();
|
let output = child.wait_with_output().unwrap();
|
||||||
|
|
||||||
@ -5720,7 +5721,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
let _ = child.wait_timeout(std::time::Duration::from_secs(20));
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
let output = child.wait_with_output().unwrap();
|
let output = child.wait_with_output().unwrap();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user