def test_iter_rpcresponses_ending_only():
    response_list = [
        Mock(payload={'id': 3, 'failure': False, 'ending': True}),
    ]

    iter_ = responses.iter_rpcresponses(response_list)

    # should not include the ending message
    assert list(iter_) == []
def test_iter_rpcresponses():
    response_list = [
        Mock(payload={'id': 1, 'failure': False, 'ending': False}),
        Mock(payload={'id': 2, 'failure': False, 'ending': False}),
        Mock(payload={'id': 3, 'failure': False, 'ending': True}),
    ]

    iter_ = responses.iter_rpcresponses(response_list)
    ret = responses.last(iter_)

    # should be the message preceeding the `ending`
    assert ret.payload['id'] == 2
예제 #3
0
def send_rpc(connection, context, exchange, topic, method, args, timeout=None):

    _log.info('rpc: %s %s.%s', exchange, topic, method)

    msgid, payload = _create_rpcpayload(context, method, args)

    with connection.channel() as channel:
        queue = get_reply_queue(msgid, channel=channel)
        queue.declare()
        _send_topic(connection, exchange, topic, payload)
        iter_ = queue_iterator(queue, timeout=timeout)
        iter_ = (msg for (_, msg) in iter_)
        iter_ = responses.iter_rpcresponses(iter_)
        ret = responses.last(iter_)
        if ret is not None:
            return ret.payload['result']