From 00e40c487e33b3ed86801ff9ca99693a192b4b7c Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Mon, 31 Aug 2015 11:26:10 -0400 Subject: [PATCH 1/2] Return messages once they are gathered If one or more messages are available, stop waiting and return them. --- moto/sqs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 31d919d87..bd4129dc2 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -281,7 +281,7 @@ class SQSBackend(BaseBackend): if len(result) >= count: break - if time.time() > polling_end: + if result or time.time() > polling_end: break return result From 7470a9f68b5de9311a79770a9f4d9631fd4a4cdd Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Mon, 31 Aug 2015 11:54:17 -0400 Subject: [PATCH 2/2] update test_messages_polling to assume messages are returned immediately --- tests/test_sqs/test_server.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_sqs/test_server.py b/tests/test_sqs/test_server.py index 56888ca5c..c7411193a 100644 --- a/tests/test_sqs/test_server.py +++ b/tests/test_sqs/test_server.py @@ -53,10 +53,14 @@ def test_messages_polling(): time.sleep(.5) def get_messages(): - msg_res = test_client.get( - '/123/testqueue?Action=ReceiveMessage&MaxNumberOfMessages=1&WaitTimeSeconds=5' - ) - [messages.append(m) for m in re.findall("(.*?)", msg_res.data.decode('utf-8'))] + count = 0 + while count < 5: + msg_res = test_client.get( + '/123/testqueue?Action=ReceiveMessage&MaxNumberOfMessages=1&WaitTimeSeconds=5' + ) + new_msgs = re.findall("(.*?)", msg_res.data.decode('utf-8')) + count += len(new_msgs) + messages.append(new_msgs) get_messages_thread = threading.Thread(target=get_messages) insert_messages_thread = threading.Thread(target=insert_messages) @@ -67,4 +71,5 @@ def test_messages_polling(): get_messages_thread.join() insert_messages_thread.join() + # got each message in a separate call to ReceiveMessage, despite the long WaitTimeSeconds assert len(messages) == 5