Exemple #1
0
    async def test_setting_resume_allows_completion(self, flow, agent):
        flow_run_id = await api.runs.create_flow_run(flow_id=flow.server_id)
        await agent.run_scheduled(flow_id=flow.server_id)
        # wait for states to be written to the db
        await asyncio.sleep(1.5)

        tr = await models.TaskRun.where(
            {
                "flow_run_id": {"_eq": flow_run_id},
                "task": {"slug": {"_eq": flow.b.slug}},
            }
        ).first({"id"})

        # put tr in a resume state
        await api.states.set_task_run_state(tr.id, Resume())

        await agent.run_scheduled(flow_id=flow.server_id)
        # wait for states to be written to the db
        await asyncio.sleep(1.5)

        fr = await models.FlowRun.where(id=flow_run_id).first(
            {
                "serialized_state": True,
                "task_runs": {"task": {"slug"}, "serialized_state": True},
            },
        )
        task_states = {
            tr.task.slug: state_schema.load(tr.serialized_state) for tr in fr.task_runs
        }
        assert fr.serialized_state["type"] == "Success"
        assert {tr.is_successful() for tr in task_states.values()}
Exemple #2
0
    def test_pause_task_doesnt_pause_sometimes(self):
        class OneTask(Task):
            def run(self):
                tasks.pause_task()
                return 1

        class AddTask(Task):
            def run(self, x, y):
                if x == y:
                    tasks.pause_task()
                return x + y

        with Flow(name="test") as f:
            t1 = AddTask()(1, 1)
            t2 = OneTask()(upstream_tasks=[t1])

        res = FlowRunner(flow=f).run(task_states={t1: Resume()}, return_tasks=[t1, t2])
        assert res.result[t1].is_successful()
        assert isinstance(res.result[t2], Paused)
    def test_manual_only_trigger_caches_inputs(self, executor):
        with Flow(name="test") as f:
            x = Parameter("x")
            inp = SuccessTask()
            t = AddTask(trigger=manual_only)
            res = t(x, inp)

        first_state = FlowRunner(flow=f).run(executor=executor,
                                             parameters=dict(x=11),
                                             return_tasks=f.tasks)
        assert first_state.is_running()

        first_state.result.update(
            {res: Resume(cached_inputs=first_state.result[res].cached_inputs)})
        second_state = FlowRunner(flow=f).run(
            executor=executor,
            parameters=dict(x=1),
            return_tasks=[res],
            task_states=first_state.result,
        )
        assert isinstance(second_state, Success)
        assert second_state.result[res].result == 12
Exemple #4
0
@pytest.mark.parametrize(
    "state_check",
    [
        dict(state=Cancelled(), assert_true={"is_finished"}),
        dict(state=Cached(),
             assert_true={"is_cached", "is_finished", "is_successful"}),
        dict(state=ClientFailed(), assert_true={"is_meta_state"}),
        dict(state=Failed(), assert_true={"is_finished", "is_failed"}),
        dict(state=Finished(), assert_true={"is_finished"}),
        dict(state=Looped(), assert_true={"is_finished", "is_looped"}),
        dict(state=Mapped(),
             assert_true={"is_finished", "is_mapped", "is_successful"}),
        dict(state=Paused(), assert_true={"is_pending", "is_scheduled"}),
        dict(state=Pending(), assert_true={"is_pending"}),
        dict(state=Queued(), assert_true={"is_meta_state", "is_queued"}),
        dict(state=Resume(), assert_true={"is_pending", "is_scheduled"}),
        dict(state=Retrying(),
             assert_true={"is_pending", "is_scheduled", "is_retrying"}),
        dict(state=Running(), assert_true={"is_running"}),
        dict(state=Scheduled(), assert_true={"is_pending", "is_scheduled"}),
        dict(state=Skipped(),
             assert_true={"is_finished", "is_successful", "is_skipped"}),
        dict(state=Submitted(), assert_true={"is_meta_state", "is_submitted"}),
        dict(state=Success(), assert_true={"is_finished", "is_successful"}),
        dict(state=TimedOut(), assert_true={"is_finished", "is_failed"}),
        dict(state=TriggerFailed(), assert_true={"is_finished", "is_failed"}),
    ],
)
def test_state_is_methods(state_check):
    """
    Iterates over all of the "is_*()" methods of the state, asserting that each one is
def test_manual_only_with_resume_state():
    """Passing a resume state from upstream should have no impact"""
    with pytest.raises(signals.PAUSE):
        triggers.manual_only({Success(), Resume()})
Exemple #6
0
 def test_state_type_methods_with_resume_state(self):
     state = Resume()
     assert state.is_pending()
     assert not state.is_retrying()
     assert not state.is_cached()
     assert not state.is_running()
     assert not state.is_finished()
     assert not state.is_skipped()
     assert state.is_scheduled()
     assert not state.is_successful()
     assert not state.is_failed()
     assert not state.is_mapped()
     assert not state.is_meta_state()