mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	cleanup
This commit is contained in:
		| @@ -40,20 +40,20 @@ script: | ||||
|       - lambda: |- | ||||
|           auto *component1 = id(test_sensor1); | ||||
|           // Test 1: Static string literals with set_timeout | ||||
|           App.scheduler.set_timeout(component1, "static_timeout_1", 100, []() { | ||||
|           App.scheduler.set_timeout(component1, "static_timeout_1", 50, []() { | ||||
|             ESP_LOGI("test", "Static timeout 1 fired"); | ||||
|             id(timeout_counter) += 1; | ||||
|           }); | ||||
|  | ||||
|           // Test 2: Static const char* with set_timeout | ||||
|           static const char* TIMEOUT_NAME = "static_timeout_2"; | ||||
|           App.scheduler.set_timeout(component1, TIMEOUT_NAME, 200, []() { | ||||
|           App.scheduler.set_timeout(component1, TIMEOUT_NAME, 100, []() { | ||||
|             ESP_LOGI("test", "Static timeout 2 fired"); | ||||
|             id(timeout_counter) += 1; | ||||
|           }); | ||||
|  | ||||
|           // Test 3: Static string literal with set_interval | ||||
|           App.scheduler.set_interval(component1, "static_interval_1", 500, []() { | ||||
|           App.scheduler.set_interval(component1, "static_interval_1", 200, []() { | ||||
|             ESP_LOGI("test", "Static interval 1 fired, count: %d", id(interval_counter)); | ||||
|             id(interval_counter) += 1; | ||||
|             if (id(interval_counter) >= 3) { | ||||
| @@ -63,7 +63,7 @@ script: | ||||
|           }); | ||||
|  | ||||
|           // Test 4: Empty string (should be handled safely) | ||||
|           App.scheduler.set_timeout(component1, "", 300, []() { | ||||
|           App.scheduler.set_timeout(component1, "", 150, []() { | ||||
|             ESP_LOGI("test", "Empty string timeout fired"); | ||||
|           }); | ||||
|  | ||||
| @@ -75,14 +75,14 @@ script: | ||||
|  | ||||
|           // Test 5: Dynamic string with set_timeout (std::string) | ||||
|           std::string dynamic_name = "dynamic_timeout_" + std::to_string(id(dynamic_counter)++); | ||||
|           App.scheduler.set_timeout(component2, dynamic_name, 150, []() { | ||||
|           App.scheduler.set_timeout(component2, dynamic_name, 100, []() { | ||||
|             ESP_LOGI("test", "Dynamic timeout fired"); | ||||
|             id(timeout_counter) += 1; | ||||
|           }); | ||||
|  | ||||
|           // Test 6: Dynamic string with set_interval | ||||
|           std::string interval_name = "dynamic_interval_" + std::to_string(id(dynamic_counter)++); | ||||
|           App.scheduler.set_interval(component2, interval_name, 600, [interval_name]() { | ||||
|           App.scheduler.set_interval(component2, interval_name, 250, [interval_name]() { | ||||
|             ESP_LOGI("test", "Dynamic interval fired: %s", interval_name.c_str()); | ||||
|             id(interval_counter) += 1; | ||||
|             if (id(interval_counter) >= 6) { | ||||
| @@ -93,7 +93,7 @@ script: | ||||
|  | ||||
|           // Test 7: Cancel with different string object but same content | ||||
|           std::string cancel_name = "cancel_test"; | ||||
|           App.scheduler.set_timeout(component2, cancel_name, 5000, []() { | ||||
|           App.scheduler.set_timeout(component2, cancel_name, 2000, []() { | ||||
|             ESP_LOGI("test", "This should be cancelled"); | ||||
|           }); | ||||
|  | ||||
| @@ -123,7 +123,7 @@ sensor: | ||||
|  | ||||
| interval: | ||||
|   # Run static string tests after boot - using script to run once | ||||
|   - interval: 0.5s | ||||
|   - interval: 0.1s | ||||
|     then: | ||||
|       - if: | ||||
|           condition: | ||||
| @@ -134,23 +134,23 @@ interval: | ||||
|             - logger.log: "Started static string tests" | ||||
|  | ||||
|   # Run dynamic string tests after static tests | ||||
|   - interval: 1s | ||||
|   - interval: 0.2s | ||||
|     then: | ||||
|       - if: | ||||
|           condition: | ||||
|             lambda: 'return id(static_tests_done) && !id(dynamic_tests_done);' | ||||
|           then: | ||||
|             - lambda: 'id(dynamic_tests_done) = true;' | ||||
|             - delay: 1s | ||||
|             - delay: 0.2s | ||||
|             - script.execute: test_dynamic_strings | ||||
|  | ||||
|   # Report results after all tests | ||||
|   - interval: 1s | ||||
|   - interval: 0.2s | ||||
|     then: | ||||
|       - if: | ||||
|           condition: | ||||
|             lambda: 'return id(dynamic_tests_done) && !id(results_reported);' | ||||
|           then: | ||||
|             - lambda: 'id(results_reported) = true;' | ||||
|             - delay: 3s | ||||
|             - delay: 1s | ||||
|             - script.execute: report_results | ||||
|   | ||||
| @@ -99,24 +99,24 @@ async def test_scheduler_string_test( | ||||
|  | ||||
|         # Wait for static string tests | ||||
|         try: | ||||
|             await asyncio.wait_for(static_timeout_1_fired.wait(), timeout=3.0) | ||||
|             await asyncio.wait_for(static_timeout_1_fired.wait(), timeout=0.5) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Static timeout 1 did not fire within 3 seconds") | ||||
|             pytest.fail("Static timeout 1 did not fire within 0.5 seconds") | ||||
|  | ||||
|         try: | ||||
|             await asyncio.wait_for(static_timeout_2_fired.wait(), timeout=3.0) | ||||
|             await asyncio.wait_for(static_timeout_2_fired.wait(), timeout=0.5) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Static timeout 2 did not fire within 3 seconds") | ||||
|             pytest.fail("Static timeout 2 did not fire within 0.5 seconds") | ||||
|  | ||||
|         try: | ||||
|             await asyncio.wait_for(static_interval_fired.wait(), timeout=3.0) | ||||
|             await asyncio.wait_for(static_interval_fired.wait(), timeout=1.0) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Static interval did not fire within 3 seconds") | ||||
|             pytest.fail("Static interval did not fire within 1 seconds") | ||||
|  | ||||
|         try: | ||||
|             await asyncio.wait_for(static_interval_cancelled.wait(), timeout=3.0) | ||||
|             await asyncio.wait_for(static_interval_cancelled.wait(), timeout=2.0) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Static interval was not cancelled within 3 seconds") | ||||
|             pytest.fail("Static interval was not cancelled within 2 seconds") | ||||
|  | ||||
|         # Verify static interval ran at least 3 times | ||||
|         assert static_interval_count >= 2, ( | ||||
| @@ -125,26 +125,26 @@ async def test_scheduler_string_test( | ||||
|  | ||||
|         # Wait for dynamic string tests | ||||
|         try: | ||||
|             await asyncio.wait_for(dynamic_timeout_fired.wait(), timeout=5.0) | ||||
|             await asyncio.wait_for(dynamic_timeout_fired.wait(), timeout=1.0) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Dynamic timeout did not fire within 5 seconds") | ||||
|             pytest.fail("Dynamic timeout did not fire within 1 seconds") | ||||
|  | ||||
|         try: | ||||
|             await asyncio.wait_for(dynamic_interval_fired.wait(), timeout=5.0) | ||||
|             await asyncio.wait_for(dynamic_interval_fired.wait(), timeout=1.5) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Dynamic interval did not fire within 5 seconds") | ||||
|             pytest.fail("Dynamic interval did not fire within 1.5 seconds") | ||||
|  | ||||
|         # Wait for cancel test | ||||
|         try: | ||||
|             await asyncio.wait_for(cancel_test_done.wait(), timeout=5.0) | ||||
|             await asyncio.wait_for(cancel_test_done.wait(), timeout=1.0) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Cancel test did not complete within 5 seconds") | ||||
|             pytest.fail("Cancel test did not complete within 1 seconds") | ||||
|  | ||||
|         # Wait for final results | ||||
|         try: | ||||
|             await asyncio.wait_for(final_results_logged.wait(), timeout=10.0) | ||||
|             await asyncio.wait_for(final_results_logged.wait(), timeout=4.0) | ||||
|         except asyncio.TimeoutError: | ||||
|             pytest.fail("Final results were not logged within 10 seconds") | ||||
|             pytest.fail("Final results were not logged within 4 seconds") | ||||
|  | ||||
|         # Verify results | ||||
|         assert timeout_count >= 3, f"Expected at least 3 timeouts, got {timeout_count}" | ||||
| @@ -154,10 +154,3 @@ async def test_scheduler_string_test( | ||||
|  | ||||
|         # Empty string timeout DOES fire (scheduler accepts empty names) | ||||
|         assert empty_string_timeout_fired.is_set(), "Empty string timeout should fire" | ||||
|  | ||||
|         # Log final status | ||||
|         print("\nScheduler string test completed successfully:") | ||||
|         print(f"  Timeouts fired: {timeout_count}") | ||||
|         print(f"  Intervals fired: {interval_count}") | ||||
|         print(f"  Static interval count: {static_interval_count + 1}") | ||||
|         print(f"  Dynamic interval count: {dynamic_interval_count}") | ||||
|   | ||||
		Reference in New Issue
	
	Block a user