Skip to content

Commit 25cb84a

Browse files
ManciukicShadowCurse
authored andcommitted
fix(tests): poll for vhost-user socket readiness instead of sleeping
Replace time.sleep(1) + bare assert in VhostUserBlkBackend.spawn() with a tenacity retry loop (50 attempts, 100ms apart). This eliminates a race condition where crosvm hasn't bound the socket yet when the assertion fires, causing intermittent test_vhost_user_block failures on aarch64. Uses the same retry pattern (wait_fixed/stop_after_attempt) already established in microvm.py. Signed-off-by: Riccardo Mancini <mancio@amazon.com>
1 parent d4b02ce commit 25cb84a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

tests/framework/utils_drive.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
import os
77
import subprocess
8-
import time
98
from abc import ABC, abstractmethod
109
from enum import Enum
1110
from pathlib import Path
1211
from subprocess import check_output
1312

13+
from tenacity import retry, stop_after_attempt, wait_fixed
14+
1415
from framework import utils
1516

1617
MB = 1024 * 1024
@@ -81,18 +82,20 @@ def spawn(self, uid, gid):
8182
args = self._spawn_cmd()
8283
proc = subprocess.Popen(args)
8384

84-
# Give the backend time to initialise.
85-
time.sleep(1)
86-
8785
assert proc is not None and proc.poll() is None, "backend is not up"
88-
assert self.socket_path.exists()
86+
self._wait_for_socket()
8987

9088
os.chown(self.socket_path, uid, gid)
9189

9290
self.proc = proc
9391

9492
return str(Path("/") / os.path.basename(self.socket_path))
9593

94+
@retry(wait=wait_fixed(0.1), stop=stop_after_attempt(50), reraise=True)
95+
def _wait_for_socket(self):
96+
"""Wait for the backend socket to appear (up to 5s)."""
97+
assert self.socket_path.exists(), f"socket {self.socket_path} not ready"
98+
9699
@abstractmethod
97100
def _spawn_cmd(self):
98101
"""Return a spawn command for the backend"""

0 commit comments

Comments
 (0)