Skip to content

Commit

Permalink
Move test task kernel to utils (#1717)
Browse files Browse the repository at this point in the history
Move `divide` to utils, and remove the recently unreferenced `div_zero`.  While
here, make the test slightly more honest by using random numbers.
  • Loading branch information
khk-globus committed Nov 13, 2024
1 parent 41a718c commit 6b32104
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 6 additions & 7 deletions compute_endpoint/tests/unit/test_execute_task.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import logging
import random
from unittest import mock

import pytest
from globus_compute_common import messagepack
from globus_compute_endpoint.engines.helper import execute_task
from tests.utils import divide

logger = logging.getLogger(__name__)

_MOCK_BASE = "globus_compute_endpoint.engines.helper."


def divide(x, y):
return x / y


@pytest.mark.parametrize("run_dir", ("tmp", None, "$HOME"))
def test_bad_run_dir(endpoint_uuid, task_uuid, run_dir):
with pytest.raises(RuntimeError):
execute_task(task_uuid, b"", endpoint_uuid, run_dir=run_dir)


def test_execute_task(endpoint_uuid, serde, task_uuid, ez_pack_task, tmp_path):
inp, outp = (10, 2), 5
out = random.randint(1, 100_000)
divisor = random.randint(1, 100_000)

task_bytes = ez_pack_task(divide, *inp)
task_bytes = ez_pack_task(divide, divisor * out, divisor)

packed_result = execute_task(task_uuid, task_bytes, endpoint_uuid, run_dir=tmp_path)
assert isinstance(packed_result, bytes)
Expand All @@ -35,7 +34,7 @@ def test_execute_task(endpoint_uuid, serde, task_uuid, ez_pack_task, tmp_path):
assert "python_version" in result.details
assert "dill_version" in result.details
assert "endpoint_id" in result.details
assert serde.deserialize(result.data) == outp
assert serde.deserialize(result.data) == out


def test_execute_task_with_exception(endpoint_uuid, task_uuid, ez_pack_task, tmp_path):
Expand Down
6 changes: 4 additions & 2 deletions compute_endpoint/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import itertools
import pathlib
import sys
Expand Down Expand Up @@ -106,8 +108,8 @@ def kill_manager():
os.killpg(manager_pgid, signal.SIGKILL)


def div_zero(x: int):
return x / 0
def divide(x: int | float, y: int | float):
return x / y


def succeed_after_n_runs(dirpath: pathlib.Path, fail_count: int = 1):
Expand Down

0 comments on commit 6b32104

Please sign in to comment.