-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.