async def test_completing_write_events_twice():

    output = Queue()
    conversation = given_a_write_events_message()

    await conversation.start(output)

    await output.get()
    payload = proto.WriteEventsCompleted()
    payload.result = msg.OperationResult.Success
    payload.first_event_number = 73
    payload.last_event_number = 73

    await conversation.respond_to(
        msg.InboundMessage(
            conversation.conversation_id,
            msg.TcpCommand.WriteEventsCompleted,
            payload.SerializeToString(),
        ),
        output,
    )

    with pytest.raises(asyncio.base_futures.InvalidStateError) as exn:

        await conversation.respond_to(
            msg.InboundMessage(
                conversation.conversation_id,
                msg.TcpCommand.WriteEventsCompleted,
                payload.SerializeToString(),
            ),
            output,
        )
async def test_one_event_response():

    output = Queue()
    conversation = given_a_write_events_message()

    await conversation.start(output)

    await output.get()
    payload = proto.WriteEventsCompleted()
    payload.result = msg.OperationResult.Success
    payload.first_event_number = 73
    payload.last_event_number = 73

    await conversation.respond_to(
        msg.InboundMessage(
            conversation.conversation_id,
            msg.TcpCommand.WriteEventsCompleted,
            payload.SerializeToString(),
        ),
        output,
    )

    result = await conversation.result

    assert result.first_event_number == 73
    assert result.last_event_number == 73
    assert result.result == msg.OperationResult.Success
    assert conversation.is_complete
Пример #3
0
    async def reply(self, message: InboundMessage, output: Queue) -> None:
        self.expect_only(TcpCommand.WriteEventsCompleted, message)
        result = proto.WriteEventsCompleted()
        result.ParseFromString(message.payload)

        self.result.set_result(result)