Skip to content

Commit 590d99a

Browse files
authored
test: Improve flaky reboot instance test; Implement retry for execute test command function (#676)
1 parent ec73e44 commit 590d99a

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

tests/integration/helpers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,22 @@ def assert_headers_in_lines(headers, lines):
149149

150150
def contains_at_least_one_of(target: Container[T], search_for: Iterable[T]):
151151
return any(v in target for v in search_for)
152+
153+
154+
def retry_exec_test_command_with_delay(
155+
args: List[str], retries: int = 3, delay: int = 2
156+
):
157+
for attempt in range(retries):
158+
process = subprocess.run(args, stdout=subprocess.PIPE)
159+
160+
# Check if the command succeeded
161+
if process.returncode == 0:
162+
return process
163+
else:
164+
print(
165+
f"Attempt {attempt + 1} failed, retrying in {delay} seconds..."
166+
)
167+
time.sleep(delay)
168+
169+
assert process.returncode == 0, f"Command failed after {retries} retries"
170+
return process

tests/integration/linodes/test_power_status.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pytest
22

3-
from tests.integration.helpers import delete_target_id, exec_test_command
3+
from tests.integration.helpers import (
4+
delete_target_id,
5+
exec_test_command,
6+
retry_exec_test_command_with_delay,
7+
)
48
from tests.integration.linodes.helpers_linodes import (
59
BASE_CMD,
610
create_linode_and_wait,
@@ -45,19 +49,21 @@ def test_create_linode_and_boot(test_linode_id):
4549
assert result, "Linode status has not changed to running from provisioning"
4650

4751

52+
@pytest.mark.flaky(reruns=3, reruns_delay=2)
4853
def test_reboot_linode(create_linode_in_running_state_for_reboot):
4954
# create linode and wait until it is in "running" state
5055
linode_id = create_linode_in_running_state_for_reboot
56+
# In case if the linode is not ready to reboot
57+
wait_until(linode_id=linode_id, timeout=240, status="running")
5158

5259
# reboot linode from "running" status
53-
exec_test_command(
54-
BASE_CMD + ["reboot", linode_id, "--text", "--no-headers"]
60+
retry_exec_test_command_with_delay(
61+
BASE_CMD + ["reboot", linode_id, "--text", "--no-headers"], 3, 20
5562
)
5663

57-
# returns false if status is not running after 240s after reboot
5864
assert wait_until(
5965
linode_id=linode_id, timeout=240, status="running"
60-
), "Linode status has not changed to running from provisioning"
66+
), "Linode status has not changed to running from provisioning after reboot"
6167

6268

6369
@pytest.mark.flaky(reruns=3, reruns_delay=2)

0 commit comments

Comments
 (0)