|
| 1 | +# Copyright 2019 HTCondor Team, Computer Sciences Department, |
| 2 | +# University of Wisconsin-Madison, WI. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +from pathlib import Path |
| 17 | + |
| 18 | +import pytest |
| 19 | + |
| 20 | +import htmap |
| 21 | + |
| 22 | +import htcondor |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture(scope = 'function') |
| 26 | +def hold_before_error(): |
| 27 | + map = htmap.map(lambda x: 1 / x, [1, 0]) |
| 28 | + |
| 29 | + schedd = htcondor.Schedd() |
| 30 | + cluster_id = map._cluster_ids[0] |
| 31 | + schedd.act(htcondor.JobAction.Hold, f"(ClusterID == {cluster_id}) && (ProcID == 0)") |
| 32 | + |
| 33 | + map.wait(holds_ok = True, errors_ok = True) |
| 34 | + |
| 35 | + assert map.component_statuses == [htmap.ComponentStatus.HELD, htmap.ComponentStatus.ERRORED] |
| 36 | + |
| 37 | + return map |
| 38 | + |
| 39 | + |
| 40 | +@pytest.fixture(scope = 'function') |
| 41 | +def error_before_hold(): |
| 42 | + map = htmap.map(lambda x: 1 / x, [0, 1]) |
| 43 | + |
| 44 | + schedd = htcondor.Schedd() |
| 45 | + cluster_id = map._cluster_ids[0] |
| 46 | + schedd.act(htcondor.JobAction.Hold, f"(ClusterID == {cluster_id}) && (ProcID == 1)") |
| 47 | + |
| 48 | + map.wait(holds_ok = True, errors_ok = True) |
| 49 | + |
| 50 | + assert map.component_statuses == [htmap.ComponentStatus.ERRORED, htmap.ComponentStatus.HELD] |
| 51 | + |
| 52 | + return map |
| 53 | + |
| 54 | + |
| 55 | +def test_can_get_error_if_hold_in_front(hold_before_error): |
| 56 | + hold_before_error.get_err(1) |
| 57 | + |
| 58 | + |
| 59 | +def test_can_get_error_if_error_in_front(error_before_hold): |
| 60 | + error_before_hold.get_err(0) |
| 61 | + |
| 62 | + |
| 63 | +def test_can_iterate_over_errors_if_hold_in_front(hold_before_error): |
| 64 | + assert len(list(hold_before_error.error_reports())) == 1 |
| 65 | + |
| 66 | + |
| 67 | +def test_can_iterate_over_errors_if_error_in_front(error_before_hold): |
| 68 | + assert len(list(error_before_hold.error_reports())) == 1 |
| 69 | + |
| 70 | + |
| 71 | +def test_can_get_errors_if_hold_in_front(hold_before_error): |
| 72 | + assert len(list(hold_before_error.errors)) == 1 |
| 73 | + |
| 74 | + |
| 75 | +def test_can_get_errors_if_error_in_front(error_before_hold): |
| 76 | + assert len(list(error_before_hold.errors)) == 1 |
0 commit comments