Split StreamState class out of SegmentBuffer (#60423)
This refactoring was pulled out of https://github.com/home-assistant/core/pull/53676 as an initial step towards reverting the addition of the SegmentBuffer class, which will be unrolled back into a for loop. The StreamState class holds the persistent state in stream that is used across stream worker instantiations, e.g. state across a retry or url expiration, which primarily handles discontinuities. By itself, this PR is not a large win until follow up PRs further simplify the SegmentBuffer class.
This commit is contained in:
parent
890790a659
commit
8ca89b10eb
4 changed files with 89 additions and 60 deletions
|
@ -23,7 +23,7 @@ import async_timeout
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.stream.core import Segment, StreamOutput
|
||||
from homeassistant.components.stream.worker import SegmentBuffer
|
||||
from homeassistant.components.stream.worker import StreamState
|
||||
|
||||
TEST_TIMEOUT = 7.0 # Lower than 9s home assistant timeout
|
||||
|
||||
|
@ -34,7 +34,7 @@ class WorkerSync:
|
|||
def __init__(self):
|
||||
"""Initialize WorkerSync."""
|
||||
self._event = None
|
||||
self._original = SegmentBuffer.discontinuity
|
||||
self._original = StreamState.discontinuity
|
||||
|
||||
def pause(self):
|
||||
"""Pause the worker before it finalizes the stream."""
|
||||
|
@ -45,7 +45,7 @@ class WorkerSync:
|
|||
logging.debug("waking blocked worker")
|
||||
self._event.set()
|
||||
|
||||
def blocking_discontinuity(self, stream: SegmentBuffer):
|
||||
def blocking_discontinuity(self, stream_state: StreamState):
|
||||
"""Intercept call to pause stream worker."""
|
||||
# Worker is ending the stream, which clears all output buffers.
|
||||
# Block the worker thread until the test has a chance to verify
|
||||
|
@ -55,7 +55,7 @@ class WorkerSync:
|
|||
self._event.wait()
|
||||
|
||||
# Forward to actual implementation
|
||||
self._original(stream)
|
||||
self._original(stream_state)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
@ -63,7 +63,7 @@ def stream_worker_sync(hass):
|
|||
"""Patch StreamOutput to allow test to synchronize worker stream end."""
|
||||
sync = WorkerSync()
|
||||
with patch(
|
||||
"homeassistant.components.stream.worker.SegmentBuffer.discontinuity",
|
||||
"homeassistant.components.stream.worker.StreamState.discontinuity",
|
||||
side_effect=sync.blocking_discontinuity,
|
||||
autospec=True,
|
||||
):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue