Skip to content

Commit

Permalink
Fix process_tree test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Nov 20, 2024
1 parent ca39f44 commit 175c214
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pytest

from _ert.forward_model_runner import forward_model_step
from _ert.forward_model_runner.forward_model_step import (
ForwardModelStep,
_get_processtree_data,
Expand Down Expand Up @@ -182,13 +183,17 @@ def oneshot(self):
return contextlib.nullcontext()


def test_cpu_seconds_for_process_with_children():
(_, cpu_seconds, _) = _get_processtree_data(MockedProcess(123))
def test_cpu_seconds_for_process_with_children(monkeypatch):
def mocked_process(pid):
return MockedProcess(123)

monkeypatch.setattr(forward_model_step, "Process", mocked_process)
(_, cpu_seconds, _) = _get_processtree_data(123)
assert cpu_seconds == 123 / 10.0 + 124 / 10.0


@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="No oom_score on MacOS")
def test_oom_score_is_max_over_processtree():
def test_oom_score_is_max_over_processtree(monkeypatch):
def read_text_side_effect(self: pathlib.Path, *args, **kwargs):
if self.absolute() == pathlib.Path("/proc/123/oom_score"):
return "234"
Expand All @@ -197,6 +202,11 @@ def read_text_side_effect(self: pathlib.Path, *args, **kwargs):

with patch("pathlib.Path.read_text", autospec=True) as mocked_read_text:
mocked_read_text.side_effect = read_text_side_effect

def mocked_process(pid):
return MockedProcess(123)

monkeypatch.setattr(forward_model_step, "Process", mocked_process)
(_, _, oom_score) = _get_processtree_data(MockedProcess(123))

assert oom_score == 456
Expand Down

0 comments on commit 175c214

Please sign in to comment.