channel and connection closing experimenting

This commit is contained in:
Matthias Bisping 2022-03-24 10:42:21 +01:00
parent e3812725ac
commit 9f4dfb9781
2 changed files with 21 additions and 12 deletions

View File

@ -129,8 +129,11 @@ class PikaQueueManager(QueueManager):
self.publish_response(message, visitor)
def clear(self):
self.channel.queue_purge(self._input_queue)
self.channel.queue_purge(self._output_queue)
try:
self.channel.queue_purge(self._input_queue)
self.channel.queue_purge(self._output_queue)
except pika.exceptions.ChannelWrongStateError:
pass
@property
def input_queue(self) -> QueueHandle:

View File

@ -123,18 +123,24 @@ def get_queue_manager(queue_manager_name) -> QueueManager:
@pytest.fixture(scope="session")
def queue_manager(queue_manager_name):
def close_connections():
if queue_manager_name == "pika":
try:
queue_manager.connection.close()
except (pika.exceptions.StreamLostError, pika.exceptions.ConnectionWrongStateError, ConnectionResetError):
logger.debug("Connection was already closed when attempting to close explicitly.")
def close_channel():
if queue_manager_name == "pika":
try:
queue_manager.channel.close()
except pika.exceptions.ChannelWrongStateError:
logger.debug("Channel was already closed when attempting to close explicitly.")
queue_manager = get_queue_manager(queue_manager_name)
yield queue_manager
if queue_manager_name == "pika":
# try:
queue_manager.connection.close()
# except (pika.exceptions.StreamLostError, ConnectionResetError):
# pass
try:
queue_manager.channel.close()
except pika.exceptions.ChannelWrongStateError:
logger.debug("Channel was already closed when attempting to close explicitly.")
pass
close_connections()
close_channel()
@pytest.fixture(scope="session")