Fix cpu percentage interpretations

This commit is contained in:
Javanaut
2026-04-11 16:30:41 +02:00
parent 52c6462fa8
commit 609f93b783
6 changed files with 92 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
from pathlib import Path
import sys
import unittest
from unittest.mock import patch
SRC_ROOT = Path(__file__).resolve().parents[2] / "src"
@@ -69,11 +70,11 @@ class ProcessTests(unittest.TestCase):
def test_get_wrapped_command_sequence_wraps_cpulimit_around_nice_when_both_configured(self):
wrapped = getWrappedCommandSequence(
["ffmpeg", "-i", "input.mkv"],
context={"resource_limits": {"niceness": 5, "cpu_percent": 42}},
context={"resource_limits": {"niceness": 5, "cpu_limit": 200}},
)
self.assertEqual(
["cpulimit", "-l", "42", "--", "nice", "-n", "5", "ffmpeg", "-i", "input.mkv"],
["cpulimit", "-l", "200", "--", "nice", "-n", "5", "ffmpeg", "-i", "input.mkv"],
wrapped,
)
@@ -83,6 +84,13 @@ class ProcessTests(unittest.TestCase):
def test_normalize_cpu_percent_accepts_disabled_sentinel(self):
self.assertIsNone(normalizeCpuPercent(0))
def test_normalize_cpu_percent_accepts_absolute_cpulimit_values(self):
self.assertEqual(200, normalizeCpuPercent(200))
def test_normalize_cpu_percent_converts_percent_of_present_cores(self):
with patch("ffx.process.getPresentCpuCount", return_value=8):
self.assertEqual(200, normalizeCpuPercent("25%"))
if __name__ == "__main__":
unittest.main()