Skip to content

Commit

Permalink
Adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yadudoc committed Nov 26, 2024
1 parent c72d52e commit 18b2ca8
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 26 deletions.
Empty file.
Empty file.
40 changes: 40 additions & 0 deletions globus_compute_executor/tests/unit/test_exec_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import copy

from globus_compute_executor.executor import GlobusComputeExecutor
from globus_compute_executor.tests.utils import MockExecutor, double


def test_bare_init():
executor = MockExecutor()
ex = GlobusComputeExecutor(executor=executor)

assert not ex.user_endpoint_config
assert not ex.resource_specification


def test_res_spec_init():
executor = MockExecutor()
res_spec = {"num_ranks": 4, "num_nodes": 2}
ex = GlobusComputeExecutor(executor=executor, resource_specification=res_spec)

assert not ex.user_endpoint_config
assert ex.resource_specification == res_spec


def test_res_spec_immutability():
"""Task submission should not modify defaults on the executor"""
executor = MockExecutor()
res_spec = {"num_ranks": 4, "num_nodes": 2}
ex = GlobusComputeExecutor(executor=executor, resource_specification=res_spec)

for task_res_spec in [
{"num_ranks": 1, "num_nodes": 1},
{"num_ranks": 5, "num_nodes": 5},
]:
for user_config in [{"blah": "blah"}, {"foo": "foo"}]:

res_spec = copy.deepcopy(task_res_spec)
res_spec["user_endpoint_config"] = user_config
res, o_res_spec, o_user_config = ex.submit(double, res_spec, 5).result()
assert task_res_spec == o_res_spec
assert user_config == o_user_config
23 changes: 23 additions & 0 deletions globus_compute_executor/tests/unit/test_passthrough.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from concurrent.futures import ThreadPoolExecutor

from globus_compute_executor.executor import GlobusComputeExecutor
from globus_compute_executor.tests.utils import double


def test_passthrough():
executor = GlobusComputeExecutor(executor=ThreadPoolExecutor())

for i in range(10):
fu = executor.submit(double, {}, i)
assert fu.result() == i * 2

executor.shutdown()


def test_shutdown():
executor = GlobusComputeExecutor(executor=ThreadPoolExecutor())

assert executor.executor._shutdown is False
executor.shutdown()

assert executor.executor._shutdown is True
24 changes: 24 additions & 0 deletions globus_compute_executor/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from concurrent.futures import Future


def double(x):
return x * 2


class MockExecutor:

def __init__(self, user_endpoint_config=None, resource_specification=None):
self.user_endpoint_config = user_endpoint_config
self.resource_specification = resource_specification

def submit(self, func, *args, **kwargs):
future = Future()
try:
result = func(*args, **kwargs)
# This will return the executor submit state
future.set_result(
(result, self.resource_specification, self.user_endpoint_config)
)
except Exception as e:
future.set_exception(exception=e)
return future
26 changes: 0 additions & 26 deletions tests/unit/test_wrapping.py

This file was deleted.

0 comments on commit 18b2ca8

Please sign in to comment.