Ejemplo n.º 1
0
def test_exception_raised_no_dlq():
    """If an exception is raised and there's no DLQ, the proc should crash,
    (without acking)."""

    proc: missive.Processor[missive.RawMessage] = missive.Processor()

    @proc.handle_for(always)
    def crash(message, ctx):
        raise RuntimeError("bad bytes!")

    with proc.test_client() as test_client:
        blank_message = missive.RawMessage(b"")
        with pytest.raises(RuntimeError):
            test_client.send(blank_message)
Ejemplo n.º 2
0
def test_no_matching_handler():
    processor: m.Processor[m.RawMessage] = m.Processor()

    @processor.handle_for(never)
    def non_matching_handler(message, ctx):
        assert False

    with processor.test_client() as test_client:

        blank_message = m.RawMessage(b"")

        with pytest.raises(RuntimeError):
            test_client.send(blank_message)

    assert blank_message not in test_client.acked
Ejemplo n.º 3
0
def test_exception_raised_with_a_dlq():
    """If an exception is raised and there's a DLQ, it's written to the DLQ,
    acked and the processor gets on with it's life."""
    proc: missive.Processor[missive.RawMessage] = missive.Processor()
    dlq: missive.DLQ = {}
    proc.set_dlq(dlq)

    @proc.handle_for(always)
    def crash(message, ctx):
        raise RuntimeError("bad bytes!")

    with proc.test_client() as test_client:
        blank_message = missive.RawMessage(b"")
        test_client.send(blank_message)
    assert dlq == {blank_message.message_id: (blank_message, "bad bytes!")}
    assert blank_message in test_client.acked
Ejemplo n.º 4
0
def test_no_matching_handler():
    """Messages for which no handler matches should be written to the DLQ"""
    dlq: Dict = {}

    processor: m.Processor[m.RawMessage] = m.Processor()
    processor.set_dlq(dlq)

    @processor.handle_for(never)
    def non_matching_handler(message, ctx):
        assert False

    with processor.test_client() as test_client:
        blank_message = m.RawMessage(b"")
        test_client.send(blank_message)

    assert blank_message in test_client.acked
    assert list(dlq.values()) == [(blank_message, "no matching handlers")]
Ejemplo n.º 5
0
def test_one_matching_handler():
    processor: m.Processor[m.RawMessage] = m.Processor()

    flag = False

    @processor.handle_for(always)
    def flip_bit(message: m.RawMessage,
                 ctx: m.HandlingContext[m.RawMessage]) -> None:
        nonlocal flag
        flag = True
        ctx.ack()

    with processor.test_client() as test_client:
        blank_message = m.RawMessage(b"")
        test_client.send(blank_message)

    assert flag
    assert blank_message in test_client.acked
Ejemplo n.º 6
0
def test_multiple_matching_handlers():
    processor: m.Processor[m.RawMessage] = m.Processor()

    @processor.handle_for(always)
    def a_matching_handler(message, ctx):
        message.ack()

    @processor.handle_for(lambda m: True)
    def another_matching_handler(message, ctx):
        message.ack()

    with processor.test_client() as test_client:

        blank_message = m.RawMessage(b"")

        with pytest.raises(RuntimeError):
            test_client.send(blank_message)

    assert blank_message not in test_client.acked
Ejemplo n.º 7
0
def test_multiple_matching_handlers():
    dlq: Dict = {}

    processor: m.Processor[m.RawMessage] = m.Processor()
    processor.set_dlq(dlq)

    @processor.handle_for(always)
    def a_matching_handler(message, ctx):
        ctx.ack(message)

    @processor.handle_for(lambda m: True)
    def another_matching_handler(message, ctx):
        message.ack()

    with processor.test_client() as test_client:
        blank_message = m.RawMessage(b"")
        test_client.send(blank_message)

    assert blank_message in test_client.acked
    assert list(dlq.values()) == [(blank_message, "multiple matching handlers")]
Ejemplo n.º 8
0
def test_no_dlq_required():
    """Test the happy path where the DLQ is never used"""
    dlq: Dict = {}

    processor: m.Processor[m.RawMessage] = m.Processor()
    processor.set_dlq(dlq)

    flag = False

    @processor.handle_for(always)
    def flip_bit(message: m.RawMessage, ctx: m.HandlingContext[m.RawMessage]) -> None:
        nonlocal flag
        flag = True
        ctx.ack()

    with processor.test_client() as test_client:
        blank_message = m.RawMessage(b"")
        test_client.send(blank_message)

    assert flag
    assert blank_message in test_client.acked
Ejemplo n.º 9
0
def test_one_matching_handler_among_multiple():
    processor: m.Processor[m.RawMessage] = m.Processor()

    flag = False

    @processor.handle_for(always)
    def a_matching_handler(message, ctx):
        nonlocal flag
        flag = True
        ctx.ack()

    @processor.handle_for(never)
    def another_handler(message, ctx):
        message.ack()

    with processor.test_client() as test_client:
        blank_message = m.RawMessage(b"")
        test_client.send(blank_message)

    assert flag
    assert blank_message in test_client.acked