Fix flaky test_stream_source timeout in generic camera tests (#158506)

This commit is contained in:
Paul Tarjan
2025-12-10 09:49:27 -07:00
committed by GitHub
parent 6b8650c6d9
commit 7629c9f280

View File

@@ -4,7 +4,7 @@ import asyncio
from datetime import timedelta
from http import HTTPStatus
from typing import Any
from unittest.mock import patch
from unittest.mock import AsyncMock, Mock, patch
import aiohttp
from freezegun.api import FrozenDateTimeFactory
@@ -37,7 +37,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from tests.common import Mock, MockConfigEntry
from tests.common import MockConfigEntry
from tests.typing import ClientSessionGenerator, WebSocketGenerator
@@ -353,10 +353,16 @@ async def test_stream_source(
stream_source = await async_get_stream_source(hass, "camera.config_test")
assert stream_source == "http://barney:betty@example.com/5a"
# Create a mock stream that doesn't actually try to connect
mock_stream = Mock()
mock_stream.add_provider = Mock()
mock_stream.start = AsyncMock()
mock_stream.endpoint_url = Mock(return_value="http://home.assistant/playlist.m3u8")
with patch(
"homeassistant.components.camera.Stream.endpoint_url",
return_value="http://home.assistant/playlist.m3u8",
) as mock_stream_url:
"homeassistant.components.camera.create_stream",
return_value=mock_stream,
):
# Request playlist through WebSocket
client = await hass_ws_client(hass)
@@ -366,7 +372,7 @@ async def test_stream_source(
msg = await client.receive_json()
# Assert WebSocket response
assert mock_stream_url.call_count == 1
assert mock_stream.endpoint_url.call_count == 1
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]