From 029732c7ca9ad642174fd99b642d0eed782ccf9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Sun, 29 Sep 2024 21:56:52 +0200 Subject: [PATCH] fix for unit tests --- CHANGELOG.md | 1 + coolamqp/__init__.py | 2 +- coolamqp/objects.py | 7 ++- tests/test_clustering/test_topic_exchanges.py | 51 +++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/test_clustering/test_topic_exchanges.py diff --git a/CHANGELOG.md b/CHANGELOG.md index cea1562..7ff17a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Since v1.3.2 they'll be put here and in release description. ======== * added docs regarding consume method. +* added testing topic exchanges # v1.4.1 ======= diff --git a/coolamqp/__init__.py b/coolamqp/__init__.py index 914b3b2..369aa3f 100644 --- a/coolamqp/__init__.py +++ b/coolamqp/__init__.py @@ -1 +1 @@ -__version__ = '1.4.2a1' +__version__ = '1.4.2a2' diff --git a/coolamqp/objects.py b/coolamqp/objects.py index 57a8b0a..675f741 100644 --- a/coolamqp/objects.py +++ b/coolamqp/objects.py @@ -244,7 +244,8 @@ class Queue(object): :param exclusive: Is this queue exclusive? :param auto_delete: Is this queue auto_delete ? :param arguments: either a list of (bytes, values) or a dict of (str, value) to pass as an extra argument - :warn PendingDeprecationWarning: if a non-exclusive auto_delete queue is created + :warning PendingDeprecationWarning: if a non-exclusive auto_delete queue is created or some other combinations + that will be soon unavailable (eg. RabbitMQ 4.0). """ __slots__ = ('name', 'durable', 'exchange', 'auto_delete', 'exclusive', 'anonymous', 'consumer_tag', 'arguments') @@ -265,6 +266,10 @@ class Queue(object): self.auto_delete = auto_delete self.exclusive = exclusive self.arguments = argumentify(arguments) + + if self.auto_delete and self.durable: + warnings.warn('This will be removed in RabbitMQ 4.0', PendingDeprecationWarning) + if self.auto_delete and not self.exclusive: warnings.warn('This will be removed in RabbitMQ 4.0', PendingDeprecationWarning) diff --git a/tests/test_clustering/test_topic_exchanges.py b/tests/test_clustering/test_topic_exchanges.py new file mode 100644 index 0000000..8959ad5 --- /dev/null +++ b/tests/test_clustering/test_topic_exchanges.py @@ -0,0 +1,51 @@ +import time +import os +import unittest +import logging + +import monotonic + +from coolamqp.clustering import Cluster +from coolamqp.objects import Exchange, Queue, NodeDefinition, Message + + +XCHG = Exchange('topic', type='topic', durable=True) +QUEUE = Queue(exchange=XCHG, exclusive=True, auto_delete=True) + + +NODE = NodeDefinition(os.environ.get('AMQP_HOST', '127.0.0.1'), 'guest', 'guest', heartbeat=20) +logging.basicConfig(level=logging.DEBUG) + + +class TestTopic(unittest.TestCase): + def setUp(self): + self.c = Cluster([NODE]) + self.c.start() + + def tearDown(self): + self.c.shutdown() + + + def test_bind_stuff(self): + self.c.declare(QUEUE).result() + self.c.bind(QUEUE, XCHG, routing_key='hello-world') + + did_receive = False + + def do(msg): + nonlocal did_receive + did_receive = True + msg.ack() + + cons, fut = self.c.consume(QUEUE, on_message=do, no_ack=False) + fut.result() + + self.c.publish(Message(b'good boy'), exchange=XCHG, routing_key='hello-world') + + start = monotonic.monotonic() + while not did_receive: + time.sleep(2) + if monotonic.monotonic() - start > 10: + self.fail("Message not received within 10 seconds") + + self.cons.cancel.result() -- GitLab