mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	cleanup
This commit is contained in:
		| @@ -211,7 +211,7 @@ void HOT Scheduler::call() { | |||||||
|   if (now - last_print > 2000) { |   if (now - last_print > 2000) { | ||||||
|     last_print = now; |     last_print = now; | ||||||
|     std::vector<std::unique_ptr<SchedulerItem>> old_items; |     std::vector<std::unique_ptr<SchedulerItem>> old_items; | ||||||
|     ESP_LOGD(TAG, "Items: count=%u, now=%" PRIu64 " (%u, %" PRIu32 ")", this->items_.size(), now, this->millis_major_, |     ESP_LOGD(TAG, "Items: count=%zu, now=%" PRIu64 " (%u, %" PRIu32 ")", this->items_.size(), now, this->millis_major_, | ||||||
|              this->last_millis_); |              this->last_millis_); | ||||||
|     while (!this->empty_()) { |     while (!this->empty_()) { | ||||||
|       this->lock_.lock(); |       this->lock_.lock(); | ||||||
|   | |||||||
| @@ -40,20 +40,20 @@ script: | |||||||
|       - lambda: |- |       - lambda: |- | ||||||
|           auto *component1 = id(test_sensor1); |           auto *component1 = id(test_sensor1); | ||||||
|           // Test 1: Static string literals with set_timeout |           // 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"); |             ESP_LOGI("test", "Static timeout 1 fired"); | ||||||
|             id(timeout_counter) += 1; |             id(timeout_counter) += 1; | ||||||
|           }); |           }); | ||||||
|  |  | ||||||
|           // Test 2: Static const char* with set_timeout |           // Test 2: Static const char* with set_timeout | ||||||
|           static const char* TIMEOUT_NAME = "static_timeout_2"; |           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"); |             ESP_LOGI("test", "Static timeout 2 fired"); | ||||||
|             id(timeout_counter) += 1; |             id(timeout_counter) += 1; | ||||||
|           }); |           }); | ||||||
|  |  | ||||||
|           // Test 3: Static string literal with set_interval |           // 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)); |             ESP_LOGI("test", "Static interval 1 fired, count: %d", id(interval_counter)); | ||||||
|             id(interval_counter) += 1; |             id(interval_counter) += 1; | ||||||
|             if (id(interval_counter) >= 3) { |             if (id(interval_counter) >= 3) { | ||||||
| @@ -63,7 +63,7 @@ script: | |||||||
|           }); |           }); | ||||||
|  |  | ||||||
|           // Test 4: Empty string (should be handled safely) |           // 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"); |             ESP_LOGI("test", "Empty string timeout fired"); | ||||||
|           }); |           }); | ||||||
|  |  | ||||||
| @@ -75,14 +75,14 @@ script: | |||||||
|  |  | ||||||
|           // Test 5: Dynamic string with set_timeout (std::string) |           // Test 5: Dynamic string with set_timeout (std::string) | ||||||
|           std::string dynamic_name = "dynamic_timeout_" + std::to_string(id(dynamic_counter)++); |           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"); |             ESP_LOGI("test", "Dynamic timeout fired"); | ||||||
|             id(timeout_counter) += 1; |             id(timeout_counter) += 1; | ||||||
|           }); |           }); | ||||||
|  |  | ||||||
|           // Test 6: Dynamic string with set_interval |           // Test 6: Dynamic string with set_interval | ||||||
|           std::string interval_name = "dynamic_interval_" + std::to_string(id(dynamic_counter)++); |           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()); |             ESP_LOGI("test", "Dynamic interval fired: %s", interval_name.c_str()); | ||||||
|             id(interval_counter) += 1; |             id(interval_counter) += 1; | ||||||
|             if (id(interval_counter) >= 6) { |             if (id(interval_counter) >= 6) { | ||||||
| @@ -93,7 +93,7 @@ script: | |||||||
|  |  | ||||||
|           // Test 7: Cancel with different string object but same content |           // Test 7: Cancel with different string object but same content | ||||||
|           std::string cancel_name = "cancel_test"; |           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"); |             ESP_LOGI("test", "This should be cancelled"); | ||||||
|           }); |           }); | ||||||
|  |  | ||||||
| @@ -123,7 +123,7 @@ sensor: | |||||||
|  |  | ||||||
| interval: | interval: | ||||||
|   # Run static string tests after boot - using script to run once |   # Run static string tests after boot - using script to run once | ||||||
|   - interval: 0.5s |   - interval: 0.1s | ||||||
|     then: |     then: | ||||||
|       - if: |       - if: | ||||||
|           condition: |           condition: | ||||||
| @@ -134,23 +134,23 @@ interval: | |||||||
|             - logger.log: "Started static string tests" |             - logger.log: "Started static string tests" | ||||||
|  |  | ||||||
|   # Run dynamic string tests after static tests |   # Run dynamic string tests after static tests | ||||||
|   - interval: 1s |   - interval: 0.2s | ||||||
|     then: |     then: | ||||||
|       - if: |       - if: | ||||||
|           condition: |           condition: | ||||||
|             lambda: 'return id(static_tests_done) && !id(dynamic_tests_done);' |             lambda: 'return id(static_tests_done) && !id(dynamic_tests_done);' | ||||||
|           then: |           then: | ||||||
|             - lambda: 'id(dynamic_tests_done) = true;' |             - lambda: 'id(dynamic_tests_done) = true;' | ||||||
|             - delay: 1s |             - delay: 0.2s | ||||||
|             - script.execute: test_dynamic_strings |             - script.execute: test_dynamic_strings | ||||||
|  |  | ||||||
|   # Report results after all tests |   # Report results after all tests | ||||||
|   - interval: 1s |   - interval: 0.2s | ||||||
|     then: |     then: | ||||||
|       - if: |       - if: | ||||||
|           condition: |           condition: | ||||||
|             lambda: 'return id(dynamic_tests_done) && !id(results_reported);' |             lambda: 'return id(dynamic_tests_done) && !id(results_reported);' | ||||||
|           then: |           then: | ||||||
|             - lambda: 'id(results_reported) = true;' |             - lambda: 'id(results_reported) = true;' | ||||||
|             - delay: 3s |             - delay: 1s | ||||||
|             - script.execute: report_results |             - script.execute: report_results | ||||||
|   | |||||||
| @@ -99,24 +99,24 @@ async def test_scheduler_string_test( | |||||||
|  |  | ||||||
|         # Wait for static string tests |         # Wait for static string tests | ||||||
|         try: |         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: |         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: |         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: |         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: |         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: |         except asyncio.TimeoutError: | ||||||
|             pytest.fail("Static interval did not fire within 3 seconds") |             pytest.fail("Static interval did not fire within 1 seconds") | ||||||
|  |  | ||||||
|         try: |         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: |         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 |         # Verify static interval ran at least 3 times | ||||||
|         assert static_interval_count >= 2, ( |         assert static_interval_count >= 2, ( | ||||||
| @@ -125,26 +125,26 @@ async def test_scheduler_string_test( | |||||||
|  |  | ||||||
|         # Wait for dynamic string tests |         # Wait for dynamic string tests | ||||||
|         try: |         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: |         except asyncio.TimeoutError: | ||||||
|             pytest.fail("Dynamic timeout did not fire within 5 seconds") |             pytest.fail("Dynamic timeout did not fire within 1 seconds") | ||||||
|  |  | ||||||
|         try: |         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: |         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 |         # Wait for cancel test | ||||||
|         try: |         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: |         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 |         # Wait for final results | ||||||
|         try: |         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: |         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 |         # Verify results | ||||||
|         assert timeout_count >= 3, f"Expected at least 3 timeouts, got {timeout_count}" |         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) |         # Empty string timeout DOES fire (scheduler accepts empty names) | ||||||
|         assert empty_string_timeout_fired.is_set(), "Empty string timeout should fire" |         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