Skip to content

Commit

Permalink
refactor(test): improve retry look in check_guest_connections
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
roypat committed Dec 13, 2024
1 parent 8ac2208 commit b530c94
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/framework/utils_vsock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from subprocess import Popen
from threading import Thread

from tenacity import Retrying, stop_after_attempt, wait_fixed

ECHO_SERVER_PORT = 5252
SERVER_ACCEPT_BACKLOG = 128
TEST_CONNECTION_COUNT = 50
Expand Down Expand Up @@ -143,13 +145,17 @@ def check_guest_connections(vm, server_port_path, blob_path, blob_hash):
)

try:
# Give socat a bit of time to create the socket
for attempt in Retrying(
wait=wait_fixed(0.2),
stop=stop_after_attempt(3),
reraise=True,
):
with attempt:
assert Path(server_port_path).exists()

# Link the listening Unix socket into the VM's jail, so that
# Firecracker can connect to it.
attempt = 0
# But 1st, give socat a bit of time to create the socket
while not Path(server_port_path).exists() and attempt < 3:
time.sleep(0.2)
attempt += 1
vm.create_jailed_resource(server_port_path)

# Increase maximum process count for the ssh service.
Expand Down

0 comments on commit b530c94

Please sign in to comment.