mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-18 07:51:27 +00:00
79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import threading
|
|
import time
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
|
|
from scene_search.caption_jobs import CaptionJobManager
|
|
|
|
|
|
class CaptionPauseTests(unittest.TestCase):
|
|
def test_pause_waits_between_units_and_resume_continues(self) -> None:
|
|
manager = CaptionJobManager(SimpleNamespace()) # type: ignore[arg-type]
|
|
manager._state.update(
|
|
{
|
|
"running": True,
|
|
"stage": "captioning",
|
|
"frames_total": 10,
|
|
"frames_completed": 3,
|
|
}
|
|
)
|
|
|
|
paused = manager.pause()
|
|
self.assertTrue(paused["pause_requested"])
|
|
|
|
finished = threading.Event()
|
|
|
|
def worker() -> None:
|
|
manager._wait_if_paused("captioning")
|
|
finished.set()
|
|
|
|
thread = threading.Thread(target=worker)
|
|
thread.start()
|
|
|
|
deadline = time.time() + 2
|
|
while time.time() < deadline and not manager.status().get("paused"):
|
|
time.sleep(0.01)
|
|
|
|
self.assertTrue(manager.status()["paused"])
|
|
self.assertFalse(finished.is_set())
|
|
|
|
resumed = manager.resume()
|
|
self.assertFalse(resumed["pause_requested"])
|
|
|
|
thread.join(timeout=2)
|
|
self.assertTrue(finished.is_set())
|
|
self.assertFalse(manager.status()["paused"])
|
|
self.assertEqual(manager.status()["stage"], "captioning")
|
|
|
|
def test_pause_during_routing_resumes_to_routing(self) -> None:
|
|
manager = CaptionJobManager(SimpleNamespace()) # type: ignore[arg-type]
|
|
manager._state.update({"running": True, "stage": "routing"})
|
|
|
|
manager.pause()
|
|
finished = threading.Event()
|
|
|
|
thread = threading.Thread(
|
|
target=lambda: (
|
|
manager._wait_if_paused("routing"),
|
|
finished.set(),
|
|
)
|
|
)
|
|
thread.start()
|
|
|
|
deadline = time.time() + 2
|
|
while time.time() < deadline and not manager.status().get("paused"):
|
|
time.sleep(0.01)
|
|
|
|
self.assertEqual(manager.status()["stage"], "paused")
|
|
manager.resume()
|
|
thread.join(timeout=2)
|
|
|
|
self.assertTrue(finished.is_set())
|
|
self.assertEqual(manager.status()["stage"], "routing")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|