core/homeassistant/components/stream
Allen Porter 65e3661f88
Repair flaky and broken stream tests in test_hls.py, and turn back on (#45025)
* Unmark tests as flaky (though still flaky)

This put tests into the broken state where they are flaky and do not yet pass

* Fix bug in test_hls_stream with incorrect path

* Enable and de-flake HLS stream tests

Background: Tests encode a fake video them start a stream to be decoded. Test
assert on the decoded segments, however there is a race with the stream worker
which can finish decoding first, and end the stream which ereases all buffers.

Breadown of fixes:
- Fix the race conditions by adding synchronization points right before the
  stream is finalized.
- Refactor StreamOutput.put so that a patch() can block the worker
  thread.  Previously, the put call would happen in the event loop which was
  not safe to block. This is a bit of a hack, but it is the simplist possible
  code change to add this synchronization and arguably provides slightly better
  separation of responsibilities from the worker anyway.
- Fix bugs in the tests that make them not pass, likely due to changes
  introduced while the tests were disabled
- Fix case where the HLS stream view recv() call returns None, indicating
  the worker finished while the request was waiting.

The tests were previously failing anywhere from 2-5% of the time on a lightly
loaded machine doing 1k iterations.  Now, have 0% flake rate.  Tested with:
$ py.test --count=1000 tests/components/strema/test_hls.py
2021-01-11 14:34:45 +01:00
..
__init__.py
const.py
core.py Repair flaky and broken stream tests in test_hls.py, and turn back on (#45025) 2021-01-11 14:34:45 +01:00
fmp4utils.py
hls.py Repair flaky and broken stream tests in test_hls.py, and turn back on (#45025) 2021-01-11 14:34:45 +01:00
manifest.json
recorder.py
services.yaml
worker.py Repair flaky and broken stream tests in test_hls.py, and turn back on (#45025) 2021-01-11 14:34:45 +01:00