Beispiel #1
0
def test_composition_id_override(stub_broker, do_work):
    group_messages = group([pipeline([do_work.message(),
                                      do_work.message()])
                            ]).build(options={"composition_id": "id"})
    assert group_messages[0].options["composition_id"] == "id"
    assert group_messages[0].options["pipe_target"][0]["options"][
        "composition_id"] == "id"
    pipeline_messages = pipeline(
        [group([do_work.message(),
                do_work.message()])]).build(composition_id="id")
    assert all(message.options["composition_id"] == "id"
               for message in pipeline_messages)
Beispiel #2
0
def test_cancel_pipeline_or_groups(stub_broker, stub_worker, cancel_backend, with_pipeline):
    # Given a cancel backend
    # And a broker with the cancel middleware
    stub_broker.add_middleware(Cancel(backend=cancel_backend))

    has_been_called = []

    # And an actor
    @remoulade.actor()
    def do_work():
        has_been_called.append(1)
        raise ValueError()

    # And this actor is declared
    stub_broker.declare_actor(do_work)

    if with_pipeline:
        g = pipeline((do_work.message() for _ in range(4)))
    else:
        g = group((do_work.message() for _ in range(4)))

    g.cancel()
    g.run()

    stub_broker.join(do_work.queue_name)
    stub_worker.join()

    # All actors should have been canceled
    assert all(cancel_backend.is_canceled(child.message_id, None) for child in g.children)
    assert len(has_been_called) == 0
def test_multiple_groups_pipelines(stub_broker, stub_worker, result_backend):
    # Given a result backend
    # And a broker with the results middleware
    stub_broker.add_middleware(Results(backend=result_backend))

    # Given an actor that stores results
    @remoulade.actor(store_results=True)
    def do_work():
        return 1

    # Given an actor that stores results
    @remoulade.actor(store_results=True)
    def do_sum(results):
        return sum(results)

    # And this actor is declared
    stub_broker.declare_actor(do_work)
    stub_broker.declare_actor(do_sum)

    pipe = pipeline(
        [group([do_work.message(), do_work.message()]), group([do_sum.message(), do_sum.message()]), do_sum.message()]
    ).run()

    result = pipe.result.get(block=True)

    assert 4 == result
def test_pipelines_flatten_child_pipelines(stub_broker):
    # Given an actor that adds two numbers together
    @remoulade.actor
    def add(x, y):
        return x + y

    # And this actor is declared
    stub_broker.declare_actor(add)

    # When I pipe a message intended for that actor and another pipeline together
    pipe = pipeline([add.message(1, 2), add.message(3) | add.message(4), add.message(5)])

    # Then the inner pipeline should be flattened into the outer pipeline
    assert len(pipe) == 4
    assert pipe.children[0].args == (1, 2)
    assert pipe.children[1].args == (3,)
    assert pipe.children[2].args == (4,)
    assert pipe.children[3].args == (5,)