mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-17 23:41:28 +00:00
Make caption startup responsive
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import threading
|
||||||
|
import unittest
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from scene_search.caption_jobs import CaptionJobManager
|
||||||
|
|
||||||
|
|
||||||
|
class CaptionAsyncStartTests(unittest.TestCase):
|
||||||
|
def test_start_returns_while_frame_selection_runs_in_background(self) -> None:
|
||||||
|
manager = CaptionJobManager(SimpleNamespace()) # type: ignore[arg-type]
|
||||||
|
entered = threading.Event()
|
||||||
|
release = threading.Event()
|
||||||
|
|
||||||
|
def slow_select(*_args, **_kwargs):
|
||||||
|
entered.set()
|
||||||
|
release.wait(timeout=5)
|
||||||
|
raise RuntimeError("test complete")
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("scene_search.caption_jobs.init_db"),
|
||||||
|
patch("scene_search.caption_jobs._select_caption_rows", side_effect=slow_select),
|
||||||
|
):
|
||||||
|
status = manager.start(["lib-a"])
|
||||||
|
self.assertTrue(status["running"])
|
||||||
|
self.assertEqual(status["stage"], "starting")
|
||||||
|
self.assertTrue(entered.wait(timeout=2))
|
||||||
|
|
||||||
|
live = manager.status()
|
||||||
|
self.assertTrue(live["running"])
|
||||||
|
self.assertEqual(live["stage"], "starting")
|
||||||
|
self.assertEqual(
|
||||||
|
live["preparing"],
|
||||||
|
"Finding frames that need captions",
|
||||||
|
)
|
||||||
|
|
||||||
|
release.set()
|
||||||
|
if manager._thread is not None:
|
||||||
|
manager._thread.join(timeout=2)
|
||||||
|
|
||||||
|
final = manager.status()
|
||||||
|
self.assertFalse(final["running"])
|
||||||
|
self.assertEqual(final["stage"], "failed")
|
||||||
|
self.assertEqual(final["error"], "test complete")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user