Optimizes niceness and cpulimit usage
This commit is contained in:
@@ -15,6 +15,9 @@ from ffx.process import ( # noqa: E402
|
||||
COMMAND_NOT_FOUND_RETURN_CODE,
|
||||
COMMAND_TIMED_OUT_RETURN_CODE,
|
||||
executeProcess,
|
||||
getWrappedCommandSequence,
|
||||
normalizeCpuPercent,
|
||||
normalizeNiceness,
|
||||
)
|
||||
|
||||
|
||||
@@ -47,6 +50,39 @@ class ProcessTests(unittest.TestCase):
|
||||
self.assertIn("Command timed out", err)
|
||||
self.assertIn(sys.executable, err)
|
||||
|
||||
def test_get_wrapped_command_sequence_leaves_command_unwrapped_when_limits_disabled(self):
|
||||
wrapped = getWrappedCommandSequence(
|
||||
["ffmpeg", "-i", "input.mkv"],
|
||||
context={"resource_limits": {"niceness": None, "cpu_percent": None}},
|
||||
)
|
||||
|
||||
self.assertEqual(["ffmpeg", "-i", "input.mkv"], wrapped)
|
||||
|
||||
def test_get_wrapped_command_sequence_wraps_nice_when_configured(self):
|
||||
wrapped = getWrappedCommandSequence(
|
||||
["ffmpeg", "-i", "input.mkv"],
|
||||
context={"resource_limits": {"niceness": 5, "cpu_percent": None}},
|
||||
)
|
||||
|
||||
self.assertEqual(["nice", "-n", "5", "ffmpeg", "-i", "input.mkv"], wrapped)
|
||||
|
||||
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}},
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
["cpulimit", "-l", "42", "--", "nice", "-n", "5", "ffmpeg", "-i", "input.mkv"],
|
||||
wrapped,
|
||||
)
|
||||
|
||||
def test_normalize_niceness_accepts_disabled_sentinel(self):
|
||||
self.assertIsNone(normalizeNiceness(99))
|
||||
|
||||
def test_normalize_cpu_percent_accepts_disabled_sentinel(self):
|
||||
self.assertIsNone(normalizeCpuPercent(0))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user