mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 06:05:26 +01:00
Fix flaky test_stream_source timeout in generic camera tests (#158506)
This commit is contained in:
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user