|
| 1 | +import logging |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +import parsl |
| 6 | +from parsl import Config |
| 7 | +from parsl.executors import HighThroughputExecutor |
| 8 | +from parsl.executors.errors import BadStateException |
| 9 | +from parsl.jobs.states import JobState, JobStatus |
| 10 | +from parsl.providers import LocalProvider |
| 11 | + |
| 12 | + |
| 13 | +class FailingProvider(LocalProvider): |
| 14 | + def submit(*args, **kwargs): |
| 15 | + raise RuntimeError("Deliberate failure of provider.submit") |
| 16 | + |
| 17 | + |
| 18 | +def local_config(): |
| 19 | + """Config to simulate failing blocks without connecting""" |
| 20 | + return Config( |
| 21 | + executors=[ |
| 22 | + HighThroughputExecutor( |
| 23 | + label="HTEX", |
| 24 | + heartbeat_period=1, |
| 25 | + heartbeat_threshold=2, |
| 26 | + poll_period=100, |
| 27 | + max_workers_per_node=1, |
| 28 | + provider=FailingProvider( |
| 29 | + init_blocks=0, |
| 30 | + max_blocks=2, |
| 31 | + min_blocks=0, |
| 32 | + ), |
| 33 | + ) |
| 34 | + ], |
| 35 | + max_idletime=0.5, |
| 36 | + strategy='htex_auto_scale', |
| 37 | + strategy_period=0.1 |
| 38 | + # this strategy period needs to be a few times smaller than the |
| 39 | + # status_polling_interval of FailingProvider, which is 5s at |
| 40 | + # time of writing |
| 41 | + ) |
| 42 | + |
| 43 | + |
| 44 | +@parsl.python_app |
| 45 | +def double(x): |
| 46 | + return x * 2 |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.local |
| 50 | +def test_disconnected_blocks(): |
| 51 | + """Test reporting of blocks that fail to connect from HTEX""" |
| 52 | + dfk = parsl.dfk() |
| 53 | + executor = dfk.executors["HTEX"] |
| 54 | + |
| 55 | + connected_blocks = executor.connected_blocks() |
| 56 | + assert not connected_blocks, "Expected 0 blocks" |
| 57 | + |
| 58 | + future = double(5) |
| 59 | + with pytest.raises(BadStateException): |
| 60 | + future.result() |
| 61 | + |
| 62 | + assert isinstance(future.exception(), BadStateException) |
| 63 | + |
| 64 | + status_dict = executor.status() |
| 65 | + assert len(status_dict) == 1, "Expected exactly 1 block" |
| 66 | + for status in status_dict.values(): |
| 67 | + assert isinstance(status, JobStatus) |
| 68 | + assert status.state == JobState.MISSING |
| 69 | + |
| 70 | + connected_blocks = executor.connected_blocks() |
| 71 | + assert connected_blocks == [], "Expected exactly 0 connected blocks" |
0 commit comments