Example #1
0
def test_celery_basic(celery_signals):
    from tests.celery_app import basic_task, error_task, propagate_task
    cmd = ['talisker.celery', 'worker', '-q', '-A', 'tests.celery_app']

    with ServerProcess(cmd) as pr:
        pr.wait_for_output(' ready.', timeout=30)
        result = basic_task.delay()
        error_result = error_task.delay()

        with request_id('myid'):
            propagate = propagate_task.delay()

        output = result.wait(timeout=3)
        with pytest.raises(Exception):
            error_result.wait(timeout=3)
        propagate.wait(timeout=3)

    assert output == 'basic'
    pr.log.assert_log(
        msg='basic task',
        extra={'task_name': 'tests.celery_app.basic_task'},
    )
    pr.log.assert_log(
        msg='propagate_task',
        extra={'request_id': 'myid'},
    )
Example #2
0
def test_celery_basic():
    cmd = ['talisker.celery', 'worker', '-q', '-A', 'tests.celery_app']

    with ServerProcess(cmd) as pr:
        pr.wait_for_output(' ready.', timeout=30)
        result = basic_task.delay()
        error_result = error_task.delay()

        output = result.wait(timeout=3)
        with pytest.raises(Exception):
            error_result.wait(timeout=3)

    assert output == 'basic'
    assert {
        'logmsg': 'basic task',
        'extra': {'task_name': 'tests.celery_app.basic_task'},
    } in pr.log
def test_celery_basic():
    try:
        import celery  # noqa
    except ImportError:
        pytest.skip('need celery installed')

    from tests.celery_app import basic_task, error_task
    cmd = ['talisker.celery', 'worker', '-q', '-A', 'tests.celery_app']

    with ServerProcess(cmd) as pr:
        pr.wait_for_output(' ready.', timeout=30)
        result = basic_task.delay()
        error_result = error_task.delay()

        output = result.wait(timeout=3)
        with pytest.raises(Exception):
            error_result.wait(timeout=3)

    assert output == 'basic'
    assert {
        'logmsg': 'basic task',
        'extra': {'task_name': 'tests.celery_app.basic_task'},
    } in pr.log