From f55a90c170940e8d77b32ef6b95926e91489cc19 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 15 Apr 2026 09:09:33 +0100 Subject: [PATCH] tests: Remove explicit sleeps from "liveness" checks The vhost-user tests uses SSH and checking the RAM to test for the liveness of the VM - replace the explicit sleep before them with `wait_until()` allowing them to potentially finish earlier. Signed-off-by: Rob Bradford --- .../tests/common/tests_wrappers.rs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cloud-hypervisor/tests/common/tests_wrappers.rs b/cloud-hypervisor/tests/common/tests_wrappers.rs index bc68cd6b6..f1f41ecb9 100644 --- a/cloud-hypervisor/tests/common/tests_wrappers.rs +++ b/cloud-hypervisor/tests/common/tests_wrappers.rs @@ -657,12 +657,13 @@ pub(crate) fn test_vhost_user_net( let desired_ram = 1024 << 20; resize_command(&api_socket, None, Some(desired_ram), None, None); - thread::sleep(std::time::Duration::new(10, 0)); - // Here by simply checking the size (through ssh), we validate // the connection is still working, which means vhost-user-net // keeps working after the resize. - assert!(guest.get_total_memory().unwrap_or_default() > 960_000); + assert!(wait_until(Duration::from_secs(10), || guest + .get_total_memory() + .unwrap_or_default() + > 960_000)); } }); @@ -790,9 +791,10 @@ pub(crate) fn test_vhost_user_blk( let desired_ram = 1024 << 20; resize_command(&api_socket, None, Some(desired_ram), None, None); - thread::sleep(std::time::Duration::new(10, 0)); - - assert!(guest.get_total_memory().unwrap_or_default() > 960_000); + assert!(wait_until(Duration::from_secs(10), || guest + .get_total_memory() + .unwrap_or_default() + > 960_000)); // Check again the content of the block device after the resize // has been performed. @@ -1025,8 +1027,10 @@ pub(crate) fn _test_virtio_fs( let desired_ram = 1024 << 20; resize_command(&api_socket, None, Some(desired_ram), None, None); - thread::sleep(std::time::Duration::new(30, 0)); - assert!(guest.get_total_memory().unwrap_or_default() > 960_000); + assert!(wait_until(Duration::from_secs(30), || guest + .get_total_memory() + .unwrap_or_default() + > 960_000)); // After the resize, check again that file1 exists and its // content is "foo".