Example #1
0
def test_cascading_changes():
    # test that completion of job, completes step, …, completes ens
    tgf = """Ensemble /0
    Realization /0/0
    Step /0/0/0
    Job /0/0/0/0
    """
    ens = _Ensemble.from_ert_trivial_graph_format(tgf)
    all_changes = list(ens.dispatch(_Event("/0/0/0/0", "JOB_STARTED")))
    all_changes += list(ens.dispatch(_Event("/0/0/0/0", "JOB_SUCCESS")))
    partial = json.dumps(
        _StateChange.changeset_to_partial(all_changes),
        sort_keys=True,
        indent=4,
        cls=_Encoder,
    )
    assert (partial == """{
    "reals": {
        "0": {
            "status": "SUCCESS",
            "steps": {
                "0": {
                    "jobs": {
                        "0": {
                            "status": "SUCCESS"
                        }
                    },
                    "status": "SUCCESS"
                }
            }
        }
    },
    "status": "SUCCESS"
}""")
Example #2
0
def test_handled_illegal_transition():
    tgf = """Ensemble /0
    Realization /0/0
    Step /0/0/0
    Job /0/0/0/0
    """
    ens = _Ensemble.from_ert_trivial_graph_format(tgf)

    # UNKNOWN -> SUCCESS is handled by the step
    gen = ens.dispatch(_Event("/0/0/0/0", "JOB_SUCCESS"))

    illegal_transition = next(gen)

    assert isinstance(illegal_transition, IllegalTransition)
    assert illegal_transition.node == ens.children[0].children[0].children[0]
    assert illegal_transition.transition.from_state == UNKNOWN
    assert illegal_transition.transition.to_state == SUCCESS

    change = next(gen)
    assert isinstance(change, _StateChange)
    assert change.node == ens.children[0].children[0].children[0]
    assert change.transition.from_state == UNKNOWN
    assert change.transition.to_state == SUCCESS

    # will cause a step to transition illegally
    # TODO: maybe just handle this in the step

    illegal_transition = next(gen)
    assert isinstance(illegal_transition, IllegalTransition)
    assert illegal_transition.node == ens.children[0].children[0]
    assert illegal_transition.transition.from_state == UNKNOWN
    assert illegal_transition.transition.to_state == SUCCESS

    with pytest.raises(StopIteration):
        next(gen)
Example #3
0
def test_equal_states_but_with_data_changes_yields_change():
    tgf = """Ensemble /0
    Realization /0/0
    Step /0/0/0
    """
    ens = _Ensemble.from_ert_trivial_graph_format(tgf)
    list(ens.dispatch(_Event("/0/0/0", "STEP_STARTED")))

    gen = ens.dispatch(_Event("/0", "ENS_STARTED", {"foo": "bar"}))
    ens_running = next(gen)

    assert ens_running.node == ens
    assert ens_running.transition.from_state == RUNNING
    assert ens_running.transition.to_state == RUNNING.with_data({"foo": "bar"})

    with pytest.raises(StopIteration):
        next(gen)
Example #4
0
def test_equal_states_yield_no_change():
    tgf = """Ensemble /0
    Realization /0/0
    Step /0/0/0
    """
    ens = _Ensemble.from_ert_trivial_graph_format(tgf)
    gen = ens.dispatch(_Event("/0", "ENS_STARTED"))
    ens_running = next(gen)

    assert ens_running.node == ens
    assert ens_running.transition.from_state == UNKNOWN
    assert ens_running.transition.to_state == RUNNING

    with pytest.raises(StopIteration):
        next(gen)

    for change in ens.dispatch(_Event("/0/0/0", "STEP_STARTED")):
        assert (change.transition.from_state !=
                change.transition.to_state), "transitioned to same state"
Example #5
0
def test_unhandled_illegal_transition():
    tgf = """Ensemble /0
    Realization /0/0
    Step /0/0/0
    Job /0/0/0/0
    """
    ens = _Ensemble.from_ert_trivial_graph_format(tgf)

    # move job to RUNNING
    deque(ens.dispatch(_Event("/0/0/0/0", "JOB_STARTED")), maxlen=0)
    deque(ens.dispatch(_Event("/0/0/0/0", "JOB_SUCCESS")), maxlen=0)

    # SUCCESS -> FAILURE is not handled by anyone
    gen = ens.dispatch(_Event("/0/0/0/0", "JOB_FAILURE"))

    illegal_transition = next(gen)
    assert isinstance(illegal_transition, IllegalTransition)
    assert illegal_transition.node == ens.children[0].children[0].children[0]
    assert illegal_transition.transition.from_state == SUCCESS
    assert illegal_transition.transition.to_state == FAILURE

    with pytest.raises(IllegalTransition):
        next(gen)