1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-03 11:52:20 +01:00

[scheduler] Fix retry race condition on cancellation (#9788)

This commit is contained in:
J. Nick Koston
2025-07-25 08:14:15 -10:00
committed by GitHub
parent 9ac10d7276
commit 88ccde4ba1
4 changed files with 104 additions and 33 deletions

View File

@@ -148,16 +148,16 @@ async def test_scheduler_retry_test(
f"Expected at least 2 intervals, got {len(backoff_intervals)}"
)
if len(backoff_intervals) >= 3:
# First interval should be ~50ms
assert 30 <= backoff_intervals[0] <= 70, (
# First interval should be ~50ms (very wide tolerance for heavy system load)
assert 20 <= backoff_intervals[0] <= 150, (
f"First interval {backoff_intervals[0]}ms not ~50ms"
)
# Second interval should be ~100ms (50ms * 2.0)
assert 80 <= backoff_intervals[1] <= 120, (
assert 50 <= backoff_intervals[1] <= 250, (
f"Second interval {backoff_intervals[1]}ms not ~100ms"
)
# Third interval should be ~200ms (100ms * 2.0)
assert 180 <= backoff_intervals[2] <= 220, (
assert 100 <= backoff_intervals[2] <= 500, (
f"Third interval {backoff_intervals[2]}ms not ~200ms"
)
@@ -175,7 +175,7 @@ async def test_scheduler_retry_test(
# Wait for cancel retry test
try:
await asyncio.wait_for(cancel_retry_done.wait(), timeout=2.0)
await asyncio.wait_for(cancel_retry_done.wait(), timeout=3.0)
except TimeoutError:
pytest.fail(
f"Cancel retry test did not complete. Count: {cancel_retry_count}"
@@ -195,8 +195,8 @@ async def test_scheduler_retry_test(
)
# Empty name retry should run at least once before being cancelled
assert 1 <= empty_name_retry_count <= 2, (
f"Expected 1-2 empty name retry attempts, got {empty_name_retry_count}"
assert 1 <= empty_name_retry_count <= 3, (
f"Expected 1-3 empty name retry attempts, got {empty_name_retry_count}"
)
assert empty_cancel_result is True, (
"Empty name retry cancel should have succeeded"