Improve stream robustness by always retrying worker (#66417)

Improve stream robustness by always retrying in the worker on failure, rather than only when
keepalive is enabled.

This will make cloud cameras like nest more robust, since they have a tendency to be flaky. This
is also needed to improve client side retry behavior because when the client attempts to retry,
the stream token is already revoked because the worker stopped.

The worker will still idle timeout if no streams are present, so it won't go on forever if no
frontend is viewing the stream.
This commit is contained in:
Allen Porter 2022-02-12 20:59:11 -08:00 committed by GitHub
parent 203bda203d
commit 0a128d006f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 9 deletions

View file

@ -16,7 +16,8 @@ from collections import deque
from http import HTTPStatus
import logging
import threading
from unittest.mock import patch
from typing import Generator
from unittest.mock import Mock, patch
from aiohttp import web
import async_timeout
@ -219,6 +220,15 @@ def hls_sync():
yield sync
@pytest.fixture(autouse=True)
def should_retry() -> Generator[Mock, None, None]:
"""Fixture to disable stream worker retries in tests by default."""
with patch(
"homeassistant.components.stream._should_retry", return_value=False
) as mock_should_retry:
yield mock_should_retry
@pytest.fixture(scope="package")
def h264_video():
"""Generate a video, shared across tests."""