mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 18:37:47 +00:00
cover
This commit is contained in:
parent
db86f87fc3
commit
5dd76966c3
36
tests/integration/fixtures/defer_fifo_simple.yaml
Normal file
36
tests/integration/fixtures/defer_fifo_simple.yaml
Normal file
@ -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:
|
29
tests/integration/test_defer_fifo_simple.py
Normal file
29
tests/integration/test_defer_fifo_simple.py
Normal file
@ -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")
|
Loading…
x
Reference in New Issue
Block a user