def test_timeout_raises_rpc_exc_on_timeout(self, eventloop): eventloop.side_effect = socket.timeout queue = Mock() with pytest.raises(RpcTimeout): list(consuming.queue_iterator(queue, timeout=0.1))
def test_timeout_reraises_if_no_timeout(self, eventloop): eventloop.side_effect = socket.timeout queue = Mock() with pytest.raises(socket.timeout): list(consuming.queue_iterator(queue, timeout=None))
def test_timeout(self, itermessages): import time itermessages.side_effect = lambda *a, **kw: time.sleep(1) queue = Mock() with pytest.raises(exceptions.WaiterTimeout): list(consuming.queue_iterator(queue, timeout=0.1))
def response_greenthread(): with get_connection() as conn: with conn.channel() as chan: queue = nova.get_topic_queue( 'test_rpc', 'test', channel=chan) queue.declare() queue_declared.send(True) msg = ifirst(queue_iterator(queue, no_ack=True, timeout=2)) msgid, ctx, method, args = nova.parse_message(msg.payload) exchange = nova.get_reply_exchange(msgid) producer = Producer(chan, exchange=exchange, routing_key=msgid) for _ in range(3): msg = dict( result='should ignore this message', failure=None, ending=False) producer.publish(msg) eventlet.sleep(0.1) msg = dict(result=args, failure=None, ending=False) producer.publish(msg) msg = dict(result=None, failure=None, ending=True) producer.publish(msg)
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_ = consuming.queue_iterator(queue, timeout=timeout) iter_ = responses.iter_rpcresponses(iter_) ret = responses.last(iter_) if ret is not None: return ret.payload['result']
def response_greenthread(): with get_connection() as conn: with conn.channel() as chan: queue = nova.get_topic_queue('test_rpc', 'test', channel=chan) queue.declare() queue_declared.send(True) msg = ifirst(queue_iterator(queue, no_ack=True, timeout=2)) msgid, _, _, args = nova.parse_message(msg.payload) exchange = nova.get_reply_exchange(msgid) producer = Producer(chan, exchange=exchange, routing_key=msgid) msg = {'result': args, 'failure': None, 'ending': False} producer.publish(msg) msg = {'result': None, 'failure': None, 'ending': True} producer.publish(msg)
def response_greenthread(): with get_connection() as conn: with conn.channel() as chan: queue = nova.get_topic_queue( 'test_rpc', 'test', channel=chan) queue.declare() queue_declared.send(True) msg = ifirst(queue_iterator(queue, no_ack=True, timeout=2)) msgid, ctx, method, args = nova.parse_message(msg.payload) exchange = nova.get_reply_exchange(msgid) producer = Producer(chan, exchange=exchange, routing_key=msgid) msg = {'result': args, 'failure': None, 'ending': False} producer.publish(msg) msg = {'result': None, 'failure': None, 'ending': True} producer.publish(msg)
def response_greenthread(): with get_connection() as conn: with conn.channel() as chan: queue = nova.get_topic_queue('test_rpc', 'test', channel=chan) queue.declare() queue_declared.send(True) msg = ifirst(queue_iterator(queue, no_ack=True, timeout=2)) msgid, _, _, args = nova.parse_message(msg.payload) exchange = nova.get_reply_exchange(msgid) producer = Producer(chan, exchange=exchange, routing_key=msgid) for _ in range(3): msg = dict(result='should ignore this message', failure=None, ending=False) producer.publish(msg) eventlet.sleep(0.1) msg = dict(result=args, failure=None, ending=False) producer.publish(msg) msg = dict(result=None, failure=None, ending=True) producer.publish(msg)
def test_no_timeout(self, drain_consumer): drain_consumer.return_value = [(1, 'foo'), (2, 'bar')] queue = Mock() res = list(consuming.queue_iterator(queue, timeout=1)) assert res == ['foo', 'bar']
def test_no_timeout(self, itermessages): itermessages.return_value = [(1, "foo"), (2, "bar")] queue = Mock() res = list(consuming.queue_iterator(queue, timeout=1)) assert res == ["foo", "bar"]