mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-03 13:26:48 +03:00
add snapshot test for go2rtc pid after restart
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
"""Tests for resolving the go2rtc pid from cpu usages."""
|
"""Tests for resolving the go2rtc pid from cpu usages."""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from frigate.stats.util import get_go2rtc_pid
|
from frigate.stats.util import get_go2rtc_pid, stats_snapshot
|
||||||
|
|
||||||
|
|
||||||
class TestGo2rtcPid(unittest.TestCase):
|
class TestGo2rtcPid(unittest.TestCase):
|
||||||
@@ -24,3 +26,45 @@ class TestGo2rtcPid(unittest.TestCase):
|
|||||||
def test_returns_none_when_go2rtc_is_not_running(self):
|
def test_returns_none_when_go2rtc_is_not_running(self):
|
||||||
self.assertIsNone(get_go2rtc_pid({"100": {"cmdline": "ffmpeg -i x"}}))
|
self.assertIsNone(get_go2rtc_pid({"100": {"cmdline": "ffmpeg -i x"}}))
|
||||||
self.assertIsNone(get_go2rtc_pid({}))
|
self.assertIsNone(get_go2rtc_pid({}))
|
||||||
|
|
||||||
|
|
||||||
|
class TestGo2rtcPidInSnapshot(unittest.TestCase):
|
||||||
|
def snapshot(self, tracking: dict, go2rtc_pid: int) -> dict:
|
||||||
|
def update_stats(stats: dict) -> None:
|
||||||
|
stats["cpu_usages"] = {
|
||||||
|
str(go2rtc_pid): {
|
||||||
|
"cmdline": "/usr/local/go2rtc/bin/go2rtc -config=x",
|
||||||
|
"cpu": str(go2rtc_pid / 100),
|
||||||
|
"mem": str(go2rtc_pid / 10),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config = SimpleNamespace(
|
||||||
|
cameras={},
|
||||||
|
telemetry=SimpleNamespace(stats=SimpleNamespace(network_bandwidth=False)),
|
||||||
|
)
|
||||||
|
hardware_stats = Mock()
|
||||||
|
hardware_stats.update_stats.side_effect = update_stats
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("frigate.stats.util.get_detector_stats", return_value={}),
|
||||||
|
patch("frigate.stats.util.embeddings_stats", return_value={}),
|
||||||
|
patch("frigate.stats.util.calculate_shm_requirements", return_value={}),
|
||||||
|
):
|
||||||
|
return stats_snapshot(config, tracking, hardware_stats)
|
||||||
|
|
||||||
|
def test_snapshot_follows_go2rtc_restart(self):
|
||||||
|
tracking = {
|
||||||
|
"camera_metrics": {},
|
||||||
|
"detectors": {},
|
||||||
|
"started": 0,
|
||||||
|
"latest_frigate_version": "",
|
||||||
|
"processes": {"go2rtc": 200, "recording": 50},
|
||||||
|
"storage_maintainer": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
first = self.snapshot(tracking, 200)["processes"]["go2rtc"]
|
||||||
|
self.assertEqual(first, {"pid": 200, "cpu": "2.0", "mem": "20.0"})
|
||||||
|
|
||||||
|
restarted = self.snapshot(tracking, 300)["processes"]["go2rtc"]
|
||||||
|
self.assertEqual(restarted, {"pid": 300, "cpu": "3.0", "mem": "30.0"})
|
||||||
|
|||||||
Reference in New Issue
Block a user