From 5dd76966c383a4512ed5a60744cacbe5d6bdb5b1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 4 Jul 2025 07:55:01 -0500 Subject: [PATCH] cover --- .../fixtures/defer_fifo_simple.yaml | 36 +++++++++++++++++++ tests/integration/test_defer_fifo_simple.py | 29 +++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/integration/fixtures/defer_fifo_simple.yaml create mode 100644 tests/integration/test_defer_fifo_simple.py diff --git a/tests/integration/fixtures/defer_fifo_simple.yaml b/tests/integration/fixtures/defer_fifo_simple.yaml new file mode 100644 index 0000000000..5cb675e77e --- /dev/null +++ b/tests/integration/fixtures/defer_fifo_simple.yaml @@ -0,0 +1,36 @@ +esphome: + name: defer-fifo-simple + on_boot: + - lambda: |- + // Simple test: defer 10 items and verify they execute in order + static int execution_order = 0; + static bool test_passed = true; + + for (int i = 0; i < 10; i++) { + int expected = i; + App.scheduler.set_timeout((Component*)nullptr, nullptr, 0, [expected]() { + ESP_LOGD("defer_test", "Deferred item %d executed, order %d", expected, execution_order); + if (execution_order != expected) { + ESP_LOGE("defer_test", "FIFO violation: expected %d but got execution order %d", expected, execution_order); + test_passed = false; + } + execution_order++; + + if (execution_order == 10) { + if (test_passed) { + ESP_LOGI("defer_test", "✓ FIFO order test PASSED - all 10 items executed in correct order"); + } else { + ESP_LOGE("defer_test", "✗ FIFO order test FAILED - items executed out of order"); + } + } + }); + } + + ESP_LOGD("defer_test", "Deferred 10 items, waiting for execution..."); + +host: + +logger: + level: DEBUG + +api: diff --git a/tests/integration/test_defer_fifo_simple.py b/tests/integration/test_defer_fifo_simple.py new file mode 100644 index 0000000000..7b3cf21737 --- /dev/null +++ b/tests/integration/test_defer_fifo_simple.py @@ -0,0 +1,29 @@ +"""Simple test that defer() maintains FIFO order.""" + +import asyncio + +import pytest + +from .types import APIClientConnectedFactory, RunCompiledFunction + + +@pytest.mark.asyncio +async def test_defer_fifo_simple( + yaml_config: str, + run_compiled: RunCompiledFunction, + api_client_connected: APIClientConnectedFactory, +) -> None: + """Test that defer() maintains FIFO order with a simple test.""" + + async with run_compiled(yaml_config), api_client_connected() as client: + # Just verify we can connect and the device is running + device_info = await client.device_info() + assert device_info is not None + assert device_info.name == "defer-fifo-simple" + + # Give the test component time to run + await asyncio.sleep(5) + + # The component will log results, we mainly want to ensure + # it doesn't crash and completes successfully + print("Defer FIFO simple test completed")