|
24 | 24 | )
|
25 | 25 | from jobbergate_agent.jobbergate.constants import INFLUXDB_MEASUREMENT
|
26 | 26 | from jobbergate_agent.settings import SETTINGS
|
27 |
| -from jobbergate_agent.utils.exception import JobbergateApiError, JobbergateAgentError |
| 27 | +from jobbergate_agent.utils.exception import JobbergateApiError, JobbergateAgentError, SbatchError |
28 | 28 |
|
29 | 29 |
|
30 | 30 | @pytest.fixture()
|
@@ -84,6 +84,55 @@ async def test_fetch_job_data__success():
|
84 | 84 | )
|
85 | 85 |
|
86 | 86 |
|
| 87 | +@pytest.mark.asyncio |
| 88 | +@pytest.mark.usefixtures("mock_access_token") |
| 89 | +async def test_fetch_job_data__handles_list_in_job_state(): |
| 90 | + """ |
| 91 | + Test that the ``fetch_job_data()`` function can successfully retrieve |
| 92 | + job data from Slurm as a ``SlurmJobData`` when the job_state from slurm |
| 93 | + is reported as a list. |
| 94 | + """ |
| 95 | + mocked_sbatch = mock.MagicMock() |
| 96 | + mocked_sbatch.get_job_info.return_value = dict( |
| 97 | + job_state=["FAILED"], |
| 98 | + job_id=123, |
| 99 | + state_reason="NonZeroExitCode", |
| 100 | + foo="bar", |
| 101 | + ) |
| 102 | + |
| 103 | + result: SlurmJobData = await fetch_job_data(123, mocked_sbatch) |
| 104 | + |
| 105 | + assert result.job_id == 123 |
| 106 | + assert result.job_state == "FAILED" |
| 107 | + assert result.state_reason == "NonZeroExitCode" |
| 108 | + assert result.job_info is not None |
| 109 | + assert json.loads(result.job_info) == dict( |
| 110 | + job_state=["FAILED"], |
| 111 | + job_id=123, |
| 112 | + state_reason="NonZeroExitCode", |
| 113 | + foo="bar", |
| 114 | + ) |
| 115 | + |
| 116 | + |
| 117 | +@pytest.mark.asyncio |
| 118 | +@pytest.mark.usefixtures("mock_access_token") |
| 119 | +async def test_fetch_job_data__raises_error_if_job_state_is_invalid_list(): |
| 120 | + """ |
| 121 | + Test that the ``fetch_job_data()`` function raises an exception |
| 122 | + if the list slurm_job_state does not have exactly one value. |
| 123 | + """ |
| 124 | + mocked_sbatch = mock.MagicMock() |
| 125 | + mocked_sbatch.get_job_info.return_value = dict( |
| 126 | + job_state=[], |
| 127 | + job_id=123, |
| 128 | + state_reason="NonZeroExitCode", |
| 129 | + foo="bar", |
| 130 | + ) |
| 131 | + |
| 132 | + with pytest.raises(SbatchError, match="does not have exactly one value"): |
| 133 | + await fetch_job_data(123, mocked_sbatch) |
| 134 | + |
| 135 | + |
87 | 136 | @pytest.mark.asyncio
|
88 | 137 | @pytest.mark.usefixtures("mock_access_token")
|
89 | 138 | async def test_fetch_job_data__reports_status_as_UNKOWN_if_slurm_job_id_is_not_found():
|
|
0 commit comments