Fix cpu percentage interpretations
This commit is contained in:
@@ -99,6 +99,38 @@ class CliLazyImportTests(unittest.TestCase):
|
||||
result["modules"],
|
||||
)
|
||||
|
||||
def test_convert_help_describes_absolute_and_percent_cpu_limits(self):
|
||||
result = self.run_python(
|
||||
textwrap.dedent(
|
||||
f"""
|
||||
import click
|
||||
import json
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, {str(SRC_ROOT)!r})
|
||||
|
||||
import ffx.cli
|
||||
|
||||
help_output = ffx.cli.convert.get_help(click.Context(ffx.cli.convert))
|
||||
|
||||
print(json.dumps({{
|
||||
"output": help_output,
|
||||
"modules": {{
|
||||
module_name: module_name in sys.modules
|
||||
for module_name in {HEAVY_MODULES!r}
|
||||
}},
|
||||
}}))
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
self.assertIn("200", result["output"])
|
||||
self.assertIn("25%", result["output"])
|
||||
self.assertTrue(
|
||||
all(not is_loaded for is_loaded in result["modules"].values()),
|
||||
result["modules"],
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -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