Skip to content

Commit b820ec6

Browse files
committed
fix(test): retry reading pid file a few times
Sometimes, tests intermittently fail with FileNotFoundError: [Errno 2] No such file or directory: '/[snip]/root/firecracker.pid' or ValueError: invalid literal for int() with base 10: '' framework/microvm.py:485: in firecracker_pid return int(self.jailer.pid_file.read_text(encoding="ascii")) It seems this is because we check the pid file too early (especially when creating the memory monitor), so give it a few retries. Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent ba13237 commit b820ec6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tests/framework/microvm.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pathlib import Path
2828
from typing import Optional
2929

30-
from tenacity import retry, stop_after_attempt, wait_fixed
30+
from tenacity import Retrying, retry, stop_after_attempt, wait_fixed
3131

3232
import host_tools.cargo_build as build_tools
3333
import host_tools.network as net_tools
@@ -481,8 +481,16 @@ def firecracker_pid(self):
481481
"""
482482
if not self._spawned:
483483
return None
484-
# Read the PID stored inside the file.
485-
return int(self.jailer.pid_file.read_text(encoding="ascii"))
484+
485+
# Read the PID from Firecracker's pidfile. Retry if
486+
# file doesn't exist yet, or doesn't yet contain an integer
487+
for attempt in Retrying(
488+
stop=stop_after_attempt(5),
489+
wait=wait_fixed(0.1),
490+
reraise=True,
491+
):
492+
with attempt:
493+
return int(self.jailer.pid_file.read_text(encoding="ascii"))
486494

487495
@property
488496
def dimensions(self):

0 commit comments

Comments
 (0)