Exemple #1
0
    def test_cancel_on_disconnect(self, mock_queues):
        # 'mock' queue manager with an instance that we control to test the
        # disconnect callback more easily.
        qm = queues.QueueManager('TWYLA_')
        mock_queues.QueueManager.return_value = qm

        async def listen():
            event_bus = EventBus('TWYLA_')
            event_bus.listen('a-domain.to-be-listened', 'testing', noop)
            await event_bus.start()

        async def stopper():
            while qm.protocol is None:
                await asyncio.sleep(1)
            await qm.protocol.close()

        tasks = [
            asyncio.ensure_future(listen()),
            asyncio.ensure_future(stopper())
        ]

        loop = asyncio.get_event_loop()
        loop.run_until_complete(asyncio.wait(tasks))
        open_tasks = [t for t in asyncio.Task.all_tasks() if not t.done()]
        assert len(open_tasks) == 0
 def test_load_configuration_with_prefix(self):
     qm = queues.QueueManager('TWYLA_')
     assert qm.config['amqp_host'] == 'localhost'
     assert qm.config['amqp_port'] == '5672'
     assert qm.config['amqp_user'] == 'guest'
     assert qm.config['amqp_pass'] == 'guest'
     assert qm.config['amqp_vhost'] == '/'
    def test_declare_exchange(self):
        qm = queues.QueueManager('TWYLA_')
        loop = asyncio.get_event_loop()

        async def doit():
            await qm.connect()
            await qm.declare_exchange("emit-domain")

        loop.run_until_complete(doit())
        exchanges = self.rabbit.exchanges()
        assert 'emit-domain' in [x['name'] for x in exchanges]
Exemple #4
0
    def test_queue_manager_basic(self, mock_aioamqp):
        qm = queues.QueueManager('TWYLA_')
        helpers.aio_run(qm.connect())

        # Check if the return value of the connect method sets the protocol
        # and channel properly
        assert isinstance(qm.protocol, MockProtocol)
        assert isinstance(qm.channel, MockChannel)

        assert qm.protocol.channel_calls == 1
        # no exchanges or queues called yet
        assert qm.channel.exchange_declare_calls == 0
        assert qm.channel.queue_declare_calls == 0
        assert qm.channel.queue_bind_calls == 0

        helpers.aio_run(qm.stop())

        assert qm.protocol.close_calls == 1
        assert qm.channel.close_calls == 1
    def test_declare_queues_and_exchanges_for_listener(self):
        qm = queues.QueueManager('TWYLA_')
        loop = asyncio.get_event_loop()

        async def doit():
            await qm.connect()
            await qm.listen('a-domain.an-event', 'the-group', noop)

        loop.run_until_complete(doit())
        rabbit_queues = self.rabbit.queues()
        assert 'a-domain.an-event.the-group' in [
            x['name'] for x in rabbit_queues
        ]
        bindings = self.rabbit.queue_bindings('a-domain.an-event.the-group')
        assert len(bindings) == 2
        binding_to_exchange = [
            x for x in bindings if x['source'] == 'a-domain'
        ]
        assert len(binding_to_exchange) == 1
        assert binding_to_exchange[0]['routing_key'] == 'an-event'
Exemple #6
0
 def __init__(self, config_prefix: str):
     self.config_prefix = config_prefix
     self.event_listeners = {}
     self.run_stop_on_queue_close = True
     self.queue_manager = queues.QueueManager(config_prefix)
 def test_raise_exception_on_invalid_event_name(self):
     qm = queues.QueueManager('TWYLA_')
     loop = asyncio.get_event_loop()
     with pytest.raises(AssertionError):
         loop.run_until_complete(qm.listen('an-event', 'the-group', noop))