mirror of
https://github.com/esphome/esphome.git
synced 2025-08-05 09:57:47 +00:00
cover
This commit is contained in:
parent
7d3cdd15ad
commit
64ac0d2bde
@ -16,7 +16,7 @@ void SchedulerBulkCleanupComponent::trigger_bulk_cleanup() {
|
||||
ESP_LOGI(TAG, "Scheduling 25 timeouts...");
|
||||
for (int i = 0; i < 25; i++) {
|
||||
std::string name = "bulk_timeout_" + std::to_string(i);
|
||||
App.scheduler.set_timeout(this, name, 10000, [i]() {
|
||||
App.scheduler.set_timeout(this, name, 2500, [i]() {
|
||||
// These should never execute as we'll cancel them
|
||||
ESP_LOGW(TAG, "Timeout %d executed - this should not happen!", i);
|
||||
});
|
||||
@ -38,7 +38,7 @@ void SchedulerBulkCleanupComponent::trigger_bulk_cleanup() {
|
||||
|
||||
// Schedule an interval that will execute multiple times to ensure cleanup happens
|
||||
static int cleanup_check_count = 0;
|
||||
App.scheduler.set_interval(this, "cleanup_checker", 100, [this]() {
|
||||
App.scheduler.set_interval(this, "cleanup_checker", 25, [this]() {
|
||||
cleanup_check_count++;
|
||||
ESP_LOGI(TAG, "Cleanup check %d - scheduler still running", cleanup_check_count);
|
||||
|
||||
@ -54,7 +54,7 @@ void SchedulerBulkCleanupComponent::trigger_bulk_cleanup() {
|
||||
// Also schedule some normal timeouts to ensure scheduler keeps working after cleanup
|
||||
for (int i = 0; i < 5; i++) {
|
||||
std::string name = "post_cleanup_" + std::to_string(i);
|
||||
App.scheduler.set_timeout(this, name, 200 + i * 100,
|
||||
App.scheduler.set_timeout(this, name, 50 + i * 25,
|
||||
[i]() { ESP_LOGI(TAG, "Post-cleanup timeout %d executed correctly", i); });
|
||||
}
|
||||
}
|
||||
|
@ -37,9 +37,10 @@ async def test_scheduler_bulk_cleanup(
|
||||
"before": 0,
|
||||
"after": 0,
|
||||
}
|
||||
post_cleanup_executed = 0
|
||||
|
||||
def on_log_line(line: str) -> None:
|
||||
nonlocal bulk_cleanup_triggered
|
||||
nonlocal bulk_cleanup_triggered, post_cleanup_executed
|
||||
|
||||
# Look for logs indicating bulk cleanup was triggered
|
||||
# The actual cleanup happens silently, so we track the cancel operations
|
||||
@ -58,9 +59,19 @@ async def test_scheduler_bulk_cleanup(
|
||||
cleanup_stats["before"] = int(match.group(1))
|
||||
cleanup_stats["after"] = int(match.group(2))
|
||||
|
||||
# Check for test completion
|
||||
if "Bulk cleanup test complete" in line and not test_complete_future.done():
|
||||
test_complete_future.set_result(None)
|
||||
# Track post-cleanup timeout executions
|
||||
if "Post-cleanup timeout" in line and "executed correctly" in line:
|
||||
match = re.search(r"Post-cleanup timeout (\d+) executed correctly", line)
|
||||
if match:
|
||||
post_cleanup_executed += 1
|
||||
# All 5 post-cleanup timeouts have executed
|
||||
if post_cleanup_executed >= 5 and not test_complete_future.done():
|
||||
test_complete_future.set_result(None)
|
||||
|
||||
# Check for bulk cleanup completion (but don't end test yet)
|
||||
if "Bulk cleanup test complete" in line:
|
||||
# This just means the interval finished, not that all timeouts executed
|
||||
pass
|
||||
|
||||
async with (
|
||||
run_compiled(yaml_config, line_callback=on_log_line),
|
||||
@ -105,3 +116,8 @@ async def test_scheduler_bulk_cleanup(
|
||||
assert cleanup_stats["removed"] > 10, (
|
||||
f"Expected more than 10 items removed, got {cleanup_stats['removed']}"
|
||||
)
|
||||
|
||||
# Verify scheduler still works after bulk cleanup
|
||||
assert post_cleanup_executed == 5, (
|
||||
f"Expected 5 post-cleanup timeouts to execute, but {post_cleanup_executed} executed"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user