Skip to content

Commit 910051f

Browse files
fix: remove redundant asyncio.sleep calls in E2E helper tests (#470)
* fix: remove redundant asyncio.sleep calls in E2E helper tests Remove three instances of `await asyncio.sleep(5)` that were immediately followed by `wait_for_entity_registration()` calls. These sleeps were completely redundant because: 1. wait_for_entity_registration() already polls with a 20-second timeout 2. The fixed 5-second sleep wastes time even when entities are ready 3. The sleeps don't improve reliability - polling handles timing naturally This change saves ~15 seconds per test run and addresses part of issue #366 regarding flaky E2E tests and technical debt from fixed sleep patterns. Also removes unused asyncio import and fixes a pre-existing f-string lint warning (string without placeholders). Relates to #366 * refactor: remove redundant comments per code review Remove explanatory comments that duplicate what the self-documenting function name `wait_for_entity_registration` already communicates. Addresses Gemini Code Assist review feedback on PR #470. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7f57e2c commit 910051f

1 file changed

Lines changed: 1 addition & 38 deletions

File tree

tests/src/e2e/workflows/config/test_helper_crud.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- Type-specific parameter validation
88
"""
99

10-
import asyncio
1110
import logging
1211

1312
import pytest
@@ -242,19 +241,7 @@ async def test_input_number_full_lifecycle(self, mcp_client, cleanup_tracker):
242241
cleanup_tracker.track("input_number", entity_id)
243242
logger.info(f"Created input_number: {entity_id}")
244243

245-
# Give HA a moment to process entity registration before polling
246-
247-
248-
await asyncio.sleep(5)
249-
250-
251-
252-
# Wait for entity to be registered (existence only, not specific state)
253-
254-
255244
entity_ready = await wait_for_entity_registration(mcp_client, entity_id)
256-
257-
258245
assert entity_ready, f"Entity {entity_id} not registered within timeout"
259246

260247
# VERIFY via state
@@ -347,19 +334,7 @@ async def test_input_select_full_lifecycle(self, mcp_client, cleanup_tracker):
347334
cleanup_tracker.track("input_select", entity_id)
348335
logger.info(f"Created input_select: {entity_id}")
349336

350-
# Give HA a moment to process entity registration before polling
351-
352-
353-
await asyncio.sleep(5)
354-
355-
356-
357-
# Wait for entity to be registered (existence only, not specific state)
358-
359-
360337
entity_ready = await wait_for_entity_registration(mcp_client, entity_id)
361-
362-
363338
assert entity_ready, f"Entity {entity_id} not registered within timeout"
364339

365340
# VERIFY via state
@@ -445,19 +420,7 @@ async def test_input_text_full_lifecycle(self, mcp_client, cleanup_tracker):
445420
cleanup_tracker.track("input_text", entity_id)
446421
logger.info(f"Created input_text: {entity_id}")
447422

448-
# Give HA a moment to process entity registration before polling
449-
450-
451-
await asyncio.sleep(5)
452-
453-
454-
455-
# Wait for entity to be registered (existence only, not specific state)
456-
457-
458423
entity_ready = await wait_for_entity_registration(mcp_client, entity_id)
459-
460-
461424
assert entity_ready, f"Entity {entity_id} not registered within timeout"
462425

463426
# DELETE
@@ -853,7 +816,7 @@ async def test_timer_full_lifecycle(self, mcp_client, cleanup_tracker):
853816
mcp_client, entity_id, "idle", timeout=10
854817
)
855818
assert state_reached, f"Timer {entity_id} not registered in idle state within timeout"
856-
logger.info(f"Timer initial state: idle")
819+
logger.info("Timer initial state: idle")
857820

858821
# START timer
859822
start_result = await mcp_client.call_tool(

0 commit comments

Comments
 (0)