From 80a5fc77850770d380a91199de1cbe3570c8acd3 Mon Sep 17 00:00:00 2001 From: Carl Oscar Aaro Date: Wed, 28 Aug 2019 21:55:08 +0200 Subject: [PATCH 1/2] Fixes race condition while draining SQS receive_messages call and shutting down service --- tomodachi/transport/aws_sns_sqs.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tomodachi/transport/aws_sns_sqs.py b/tomodachi/transport/aws_sns_sqs.py index 9ff036d36..7663e3132 100644 --- a/tomodachi/transport/aws_sns_sqs.py +++ b/tomodachi/transport/aws_sns_sqs.py @@ -133,7 +133,10 @@ async def subscribe_handler(cls: Any, obj: Any, context: Dict, func: Any, topic: async def handler(payload: Optional[str], receipt_handle: Optional[str] = None, queue_url: Optional[str] = None, message_topic: str = '') -> Any: if not payload or payload == DRAIN_MESSAGE_PAYLOAD: - await cls.delete_message(cls, receipt_handle, queue_url, context) + try: + await cls.delete_message(cls, receipt_handle, queue_url, context) + except Exception: + pass return _callback_kwargs = callback_kwargs # type: Any @@ -342,6 +345,8 @@ async def delete_message(cls: Any, receipt_handle: Optional[str], queue_url: Opt async def _delete_message() -> None: for retry in range(1, 4): + if not cls.clients or not cls.clients.get('sqs'): + cls.create_client(cls, 'sqs', context) client = cls.clients.get('sqs') try: await asyncio.wait_for(client.delete_message(ReceiptHandle=receipt_handle, QueueUrl=queue_url), timeout=30) From 72032cc4f6f8cfffc086da9056d1f1cb7196376b Mon Sep 17 00:00:00 2001 From: Carl Oscar Aaro Date: Wed, 28 Aug 2019 21:55:15 +0200 Subject: [PATCH 2/2] Added 'make pytest' --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 907e4fbdd..f90b983df 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,10 @@ tests: PYTHONPATH=. python tomodachi.py run tests/run_example_service.py PYTHONPATH=. python setup.py check -r -s +pytest: + if [[ ! "${PYTEST_INSTALLED}" ]]; then make development; fi + PYTHONPATH=. py.test -n auto tests/ + _check_release: if [[ "${RELEASED}" ]]; then echo "Version ${VERSION} is already released"; exit 1; fi