Beispiel #1
0
def test_serializer():
    """Test result serializer on event."""
    event = Event()
    event.response = {}

    result = chain(simple_add.s(1, 2),
                   group(simple_add.s(3), simple_add.s(4),
                         failing_task.s())).apply_async()

    CeleryAsyncReceiver._serialize_result(event=event, result=result)
    deserialized_result = CeleryAsyncReceiver._deserialize_result(event=event)

    assert deserialized_result.id == result.id
    assert deserialized_result.parent.id == result.parent.id
    assert deserialized_result.children[0].id == result.children[0].id
    assert deserialized_result.children[1].id == result.children[1].id
    assert deserialized_result.children[2].id == result.children[2].id
Beispiel #2
0
def test_info_extractor():
    """Test info extractor."""
    result = simple_add.s(1, 2).apply_async()

    info = _info_extractor(result, 'mytask')
    assert info['status'] == states.SUCCESS
    assert info['info'] == '3'
    assert 'id' in info
    assert info['name'] == 'mytask'
    assert info['result'] == '3'

    result = chain(simple_add.s(1, 2), simple_add.s(3)).apply_async()

    # check first task
    info = _info_extractor(result.parent, 'mytask')
    assert info['status'] == states.SUCCESS
    assert info['info'] == '3'
    assert 'id' in info
    assert info['name'] == 'mytask'
    assert info['result'] == '3'
    # check second task
    info = _info_extractor(result, 'mytask2')
    assert info['status'] == states.SUCCESS
    assert info['info'] == '6'
    assert 'id' in info
    assert info['name'] == 'mytask2'
    assert info['result'] == '6'

    result = chain(simple_add.s(1, 2),
                   group(simple_add.s(3), simple_add.s(4),
                         failing_task.s())).apply_async()

    info = _info_extractor(result.parent, 'mytask')
    assert info['status'] == states.SUCCESS
    assert info['info'] == '3'
    assert 'id' in info
    assert info['name'] == 'mytask'
    assert info['result'] == '3'

    info = _info_extractor(result.children[0], 'mytask2')
    assert info['status'] == states.SUCCESS
    assert info['info'] == '6'
    assert 'id' in info
    assert info['name'] == 'mytask2'
    assert info['result'] == '6'

    info = _info_extractor(result.children[1], 'mytask3')
    assert info['status'] == states.SUCCESS
    assert info['info'] == '7'
    assert 'id' in info
    assert info['name'] == 'mytask3'
    assert info['result'] == '7'

    fail = AsyncResult(result.children[2].id)
    info = _info_extractor(fail, 'mytask4')
    assert info['status'] == states.FAILURE
    assert 'id' in info
    assert info['name'] == 'mytask4'
def test_collect_info():
    """Test info extractor."""
    result = simple_add.s(1, 2).apply_async()

    info = collect_info('mytask', result)
    assert info['status'] == states.SUCCESS
    assert info['info'] == 3
    assert 'id' in info
    assert info['name'] == 'mytask'

    result = chain(simple_add.s(1, 2), simple_add.s(3)).apply_async()

    # check first task
    info = collect_info('mytask', result.parent)
    assert info['status'] == states.SUCCESS
    assert info['info'] == 3
    assert 'id' in info
    assert info['name'] == 'mytask'
    # check second task
    info = collect_info('mytask2', result)
    assert info['status'] == states.SUCCESS
    assert info['info'] == 6
    assert 'id' in info
    assert info['name'] == 'mytask2'

    result = chain(
        simple_add.s(1, 2),
        group(simple_add.s(3), simple_add.s(4), failing_task.s())
    ).apply_async()

    info = collect_info('mytask', result.parent)
    assert info['status'] == states.SUCCESS
    assert info['info'] == 3
    assert 'id' in info
    assert info['name'] == 'mytask'

    info = collect_info('mytask2', result.children[0])
    assert info['status'] == states.SUCCESS
    assert info['info'] == 6
    assert 'id' in info
    assert info['name'] == 'mytask2'

    info = collect_info('mytask3', result.children[1])
    assert info['status'] == states.SUCCESS
    assert info['info'] == 7
    assert 'id' in info
    assert info['name'] == 'mytask3'

    fail = AsyncResult(result.children[2].id)
    info = collect_info('mytask4', fail)
    assert info['status'] == states.FAILURE
    assert 'id' in info
    assert info['name'] == 'mytask4'
Beispiel #4
0
 def run(self, event):
     workflow = chain(simple_add.s(1, 2),
                      group(failing_task.s(), success_task.s()))
     self._serialize_result(event, workflow.apply_async())
     event.payload['deposit_id'] = depid
     flag_modified(event, 'payload')