def test_execute_group_error(app, create_builder):
    (workflow, builder) = create_builder('example', 'SIMPLE_GROUP_ERROR', {})
    assert (workflow['status'] == 'pending')
    assert (len(builder.canvas) == 4)
    assert (builder.canvas[0].task == 'director.tasks.workflows.start')
    assert (builder.canvas[(- 1)].task == 'director.tasks.workflows.end')
    assert (builder.canvas[1].task == 'TASK_A')
    group_tasks = builder.canvas[2].tasks
    assert (len(group_tasks) == 2)
    assert ([group_tasks[0].task, group_tasks[1].task] == ['TASK_ERROR', '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_ERROR', 'TASK_C'])
    assert (set([n.status.value for n in tasks]) == {'pending'})
    result = builder.run()
    with pytest.raises(ZeroDivisionError):
        assert result.get()
    time.sleep(0.5)
    with app.app_context():
        task_a = Task.query.filter_by(key='TASK_A').first()
        task_error = Task.query.filter_by(key='TASK_ERROR').first()
        task_c = Task.query.filter_by(key='TASK_C').first()
        workflow = Workflow.query.filter_by(id=task_a.workflow_id).first()
    assert (task_a.status.value == 'success')
    assert (task_error.status.value == 'error')
    assert (task_c.status.value == 'success')
    assert (workflow.status.value == 'error')
def test_execute_group_error(app, create_builder):
    (workflow, builder) = create_builder('example', 'SIMPLE_GROUP_ERROR', {})
    assert (workflow['status'] == 'pending')
    assert (len(builder.canvas) == 4)
    assert (builder.canvas[0].task == 'director.tasks.workflows.start')
    assert (builder.canvas[(- 1)].task == 'director.tasks.workflows.end')
    assert (builder.canvas[1].task == 'TASK_A')
    group_tasks = builder.canvas[2].tasks
    assert (len(group_tasks) == 2)
    assert ([group_tasks[0].task, group_tasks[1].task] == ['TASK_ERROR', '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_ERROR', 'TASK_C'])
    assert (set([n.status.value for n in tasks]) == {'pending'})
    result = builder.run()
    with pytest.raises(ZeroDivisionError):
        assert result.get()
    time.sleep(0.5)
    with app.app_context():
        task_a = Task.query.filter_by(key='TASK_A').first()
        task_error = Task.query.filter_by(key='TASK_ERROR').first()
        task_c = Task.query.filter_by(key='TASK_C').first()
        workflow = Workflow.query.filter_by(id=task_a.workflow_id).first()
    assert (task_a.status.value == 'success')
    assert (task_error.status.value == 'error')
    assert (task_c.status.value == 'success')
    assert (workflow.status.value == 'error')