Skip to content

Commit 879426a

Browse files
committed
Try to fix setting flight mode test in sitl
1 parent ea9d31a commit 879426a

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

radio/tests/test_FlightModesController.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import pytest
24
from pymavlink.mavutil import mavlink
35

@@ -6,6 +8,26 @@
68
WaitForMessageReturnsNone,
79
)
810

11+
FLIGHT_MODE_SET_RETRY_MAX_ATTEMPTS = 5
12+
FLIGHT_MODE_SET_RETRY_DELAY_SECS = 1
13+
14+
15+
def set_flight_mode_with_retries(
16+
droneStatus, mode_number: int, flight_mode: int
17+
) -> dict:
18+
"""Retry setting a flight mode to reduce intermittent SITL timing flakes."""
19+
last_response = {"success": False, "message": "No response"}
20+
for _ in range(FLIGHT_MODE_SET_RETRY_MAX_ATTEMPTS):
21+
last_response = droneStatus.drone.flightModesController.setFlightMode(
22+
mode_number, flight_mode
23+
)
24+
if last_response.get("success"):
25+
return last_response
26+
27+
time.sleep(FLIGHT_MODE_SET_RETRY_DELAY_SECS)
28+
29+
return last_response
30+
931

1032
@pytest.fixture(scope="module", autouse=True)
1133
def run_once_after_all_tests():
@@ -155,7 +177,7 @@ def test_setFlightMode_invalidData_copter(droneStatus):
155177

156178
@pytest.mark.copter_only
157179
def test_setFlightMode_success_copter(droneStatus):
158-
response = droneStatus.drone.flightModesController.setFlightMode(1, 2)
180+
response = set_flight_mode_with_retries(droneStatus, 1, 2)
159181
assert response == {
160182
"success": True,
161183
"message": "Flight mode 1 set to COPTER_MODE_ALT_HOLD",

0 commit comments

Comments
 (0)