From 85f984f7e2ba55a7eeffc1eb821067b321f068e7 Mon Sep 17 00:00:00 2001 From: James Garner Date: Tue, 7 Jan 2025 15:09:02 +1300 Subject: [PATCH] tests: fix flaky snap test by adding multiple retries --- tests/integration/test_snap.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_snap.py b/tests/integration/test_snap.py index dfe55aba..fa711995 100644 --- a/tests/integration/test_snap.py +++ b/tests/integration/test_snap.py @@ -66,11 +66,18 @@ def test_snap_refresh(): def test_snap_set_and_get_with_typed(): cache = snap.SnapCache() lxd = cache["lxd"] - try: - lxd.ensure(snap.SnapState.Latest, channel="latest") - except snap.SnapError: - time.sleep(60) - lxd.ensure(snap.SnapState.Latest, channel="latest") + + def try_ensure_snap(retries: int) -> None: + try: + lxd.ensure(snap.SnapState.Latest, channel="latest") + except snap.SnapError: + if retries <= 0: + raise + time.sleep(20) + try_ensure_snap(retries=retries - 1) + + try_ensure_snap(retries=10) + configs = { "true": True, "false": False,