Skip to content

Commit 77d3704

Browse files
committed
refactor(test): improve retry look in check_guest_connections
Use `tenancy.Retrying` instead of the home-grown retry loop. This has the advantage that we don't simply give up after 3 attempts, but instead raise a meaningful error message (whereas before I guess we would just fail further down the function when trying to do something that assumes the file exists). Signed-off-by: Patrick Roy <[email protected]>
1 parent 130af91 commit 77d3704

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/framework/utils_vsock.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from subprocess import Popen
1212
from threading import Thread
1313

14+
from tenacity import Retrying, stop_after_attempt, wait_fixed
15+
1416
ECHO_SERVER_PORT = 5252
1517
SERVER_ACCEPT_BACKLOG = 128
1618
TEST_CONNECTION_COUNT = 50
@@ -143,13 +145,17 @@ def check_guest_connections(vm, server_port_path, blob_path, blob_hash):
143145
)
144146

145147
try:
148+
# Give socat a bit of time to create the socket
149+
for attempt in Retrying(
150+
wait=wait_fixed(0.2),
151+
stop=stop_after_attempt(3),
152+
reraise=True,
153+
):
154+
with attempt:
155+
assert Path(server_port_path).exists()
156+
146157
# Link the listening Unix socket into the VM's jail, so that
147158
# Firecracker can connect to it.
148-
attempt = 0
149-
# But 1st, give socat a bit of time to create the socket
150-
while not Path(server_port_path).exists() and attempt < 3:
151-
time.sleep(0.2)
152-
attempt += 1
153159
vm.create_jailed_resource(server_port_path)
154160

155161
# Increase maximum process count for the ssh service.

0 commit comments

Comments
 (0)