def test_execute_chain_success(app, create_builder):
    (workflow, builder) = create_builder('example', 'SIMPLE_CHAIN', {})
    assert (workflow['status'] == 'pending')
    assert (len(builder.canvas) == 5)
    assert (builder.canvas[0].task == 'director.tasks.workflows.start')
    assert (builder.canvas[(- 1)].task == 'director.tasks.workflows.end')
    assert ([c.task for c in builder.canvas[1:(- 1)]] == ['TASK_A', 'TASK_B', 'TASK_C'])
    with app.app_context():
        tasks = Task.query.order_by(Task.created_at.asc()).all()
    assert (len(tasks) == 3)
    assert ([n.key for n in tasks] == ['TASK_A', 'TASK_B', 'TASK_C'])
    assert (set([n.status.value for n in tasks]) == {'pending'})
    result = builder.run()
    assert (result.get() is None)
    assert (result.parent.parent.parent.parent.get() is None)
    assert (result.parent.get() == 'task_c')
    assert (result.parent.state == 'SUCCESS')
    assert (result.parent.parent.get() == 'task_b')
    assert (result.parent.parent.state == 'SUCCESS')
    assert (result.parent.parent.parent.get() == 'task_a')
    assert (result.parent.parent.parent.state == 'SUCCESS')
    time.sleep(0.5)
    with app.app_context():
        tasks = Task.query.filter_by(id=tasks[0].id).all()
        workflow = Workflow.query.filter_by(id=tasks[0].workflow_id).first()
    assert (workflow.status.value == 'success')
    for task in tasks:
        assert (task.status.value == 'success')
def test_execute_chain_success(app, create_builder):
    (workflow, builder) = create_builder('example', 'SIMPLE_CHAIN', {})
    assert (workflow['status'] == 'pending')
    assert (len(builder.canvas) == 5)
    assert (builder.canvas[0].task == 'director.tasks.workflows.start')
    assert (builder.canvas[(- 1)].task == 'director.tasks.workflows.end')
    assert ([c.task for c in builder.canvas[1:(- 1)]] == ['TASK_A', 'TASK_B', 'TASK_C'])
    with app.app_context():
        tasks = Task.query.order_by(Task.created_at.asc()).all()
    assert (len(tasks) == 3)
    assert ([n.key for n in tasks] == ['TASK_A', 'TASK_B', 'TASK_C'])
    assert (set([n.status.value for n in tasks]) == {'pending'})
    result = builder.run()
    assert (result.get() is None)
    assert (result.parent.parent.parent.parent.get() is None)
    assert (result.parent.get() == 'task_c')
    assert (result.parent.state == 'SUCCESS')
    assert (result.parent.parent.get() == 'task_b')
    assert (result.parent.parent.state == 'SUCCESS')
    assert (result.parent.parent.parent.get() == 'task_a')
    assert (result.parent.parent.parent.state == 'SUCCESS')
    time.sleep(0.5)
    with app.app_context():
        tasks = Task.query.filter_by(id=tasks[0].id).all()
        workflow = Workflow.query.filter_by(id=tasks[0].workflow_id).first()
    assert (workflow.status.value == 'success')
    for task in tasks:
        assert (task.status.value == 'success')