Fix cpu percentage interpretations
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user