mirror of
https://github.com/esphome/esphome.git
synced 2025-09-03 20:02:22 +01:00
[scheduler] Eliminate more runtime string allocations from retry (#9930)
This commit is contained in:
@@ -23,6 +23,9 @@ async def test_scheduler_retry_test(
|
||||
empty_name_retry_done = asyncio.Event()
|
||||
component_retry_done = asyncio.Event()
|
||||
multiple_name_done = asyncio.Event()
|
||||
const_char_done = asyncio.Event()
|
||||
static_char_done = asyncio.Event()
|
||||
mixed_cancel_done = asyncio.Event()
|
||||
test_complete = asyncio.Event()
|
||||
|
||||
# Track retry counts
|
||||
@@ -33,16 +36,20 @@ async def test_scheduler_retry_test(
|
||||
empty_name_retry_count = 0
|
||||
component_retry_count = 0
|
||||
multiple_name_count = 0
|
||||
const_char_retry_count = 0
|
||||
static_char_retry_count = 0
|
||||
|
||||
# Track specific test results
|
||||
cancel_result = None
|
||||
empty_cancel_result = None
|
||||
mixed_cancel_result = None
|
||||
backoff_intervals = []
|
||||
|
||||
def on_log_line(line: str) -> None:
|
||||
nonlocal simple_retry_count, backoff_retry_count, immediate_done_count
|
||||
nonlocal cancel_retry_count, empty_name_retry_count, component_retry_count
|
||||
nonlocal multiple_name_count, cancel_result, empty_cancel_result
|
||||
nonlocal multiple_name_count, const_char_retry_count, static_char_retry_count
|
||||
nonlocal cancel_result, empty_cancel_result, mixed_cancel_result
|
||||
|
||||
# Strip ANSI color codes
|
||||
clean_line = re.sub(r"\x1b\[[0-9;]*m", "", line)
|
||||
@@ -106,6 +113,27 @@ async def test_scheduler_retry_test(
|
||||
if multiple_name_count >= 20:
|
||||
multiple_name_done.set()
|
||||
|
||||
# Const char retry test
|
||||
elif "Const char retry" in clean_line:
|
||||
if match := re.search(r"Const char retry (\d+)", clean_line):
|
||||
const_char_retry_count = int(match.group(1))
|
||||
const_char_done.set()
|
||||
|
||||
# Static const char retry test
|
||||
elif "Static const char retry" in clean_line:
|
||||
if match := re.search(r"Static const char retry (\d+)", clean_line):
|
||||
static_char_retry_count = int(match.group(1))
|
||||
static_char_done.set()
|
||||
|
||||
elif "Static cancel result:" in clean_line:
|
||||
# This is part of test 9, but we don't track it separately
|
||||
pass
|
||||
|
||||
# Mixed cancel test
|
||||
elif "Mixed cancel result:" in clean_line:
|
||||
mixed_cancel_result = "true" in clean_line
|
||||
mixed_cancel_done.set()
|
||||
|
||||
# Test completion
|
||||
elif "All retry tests completed" in clean_line:
|
||||
test_complete.set()
|
||||
@@ -227,6 +255,40 @@ async def test_scheduler_retry_test(
|
||||
f"Expected multiple name count >= 20 (second retry only), got {multiple_name_count}"
|
||||
)
|
||||
|
||||
# Wait for const char retry test
|
||||
try:
|
||||
await asyncio.wait_for(const_char_done.wait(), timeout=1.0)
|
||||
except TimeoutError:
|
||||
pytest.fail(
|
||||
f"Const char retry test did not complete. Count: {const_char_retry_count}"
|
||||
)
|
||||
|
||||
assert const_char_retry_count == 1, (
|
||||
f"Expected 1 const char retry call, got {const_char_retry_count}"
|
||||
)
|
||||
|
||||
# Wait for static char retry test
|
||||
try:
|
||||
await asyncio.wait_for(static_char_done.wait(), timeout=1.0)
|
||||
except TimeoutError:
|
||||
pytest.fail(
|
||||
f"Static char retry test did not complete. Count: {static_char_retry_count}"
|
||||
)
|
||||
|
||||
assert static_char_retry_count == 1, (
|
||||
f"Expected 1 static char retry call, got {static_char_retry_count}"
|
||||
)
|
||||
|
||||
# Wait for mixed cancel test
|
||||
try:
|
||||
await asyncio.wait_for(mixed_cancel_done.wait(), timeout=1.0)
|
||||
except TimeoutError:
|
||||
pytest.fail("Mixed cancel test did not complete")
|
||||
|
||||
assert mixed_cancel_result is True, (
|
||||
"Mixed string/const char cancel should have succeeded"
|
||||
)
|
||||
|
||||
# Wait for test completion
|
||||
try:
|
||||
await asyncio.wait_for(test_complete.wait(), timeout=1.0)
|
||||
|
Reference in New Issue
Block a user