SQS: send_message() should respect DelaySeconds of 0 (#7373)

This commit is contained in:
Bert Blommers 2024-02-20 23:07:18 +00:00 committed by GitHub
parent f7b8a92212
commit f9add957c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -845,7 +845,7 @@ class SQSBackend(BaseBackend):
self._validate_message(queue, message_body, deduplication_id, group_id) self._validate_message(queue, message_body, deduplication_id, group_id)
if delay_seconds: if delay_seconds is not None:
delay_seconds = int(delay_seconds) delay_seconds = int(delay_seconds)
else: else:
delay_seconds = queue.delay_seconds # type: ignore delay_seconds = queue.delay_seconds # type: ignore

View File

@ -308,7 +308,7 @@ class SQSResponse(BaseResponse):
@jsonify_error @jsonify_error
def send_message(self) -> Union[str, TYPE_RESPONSE]: def send_message(self) -> Union[str, TYPE_RESPONSE]:
message = self._get_param("MessageBody") message = self._get_param("MessageBody")
delay_seconds = int(self._get_param("DelaySeconds", 0)) delay_seconds = self._get_param("DelaySeconds")
message_group_id = self._get_param("MessageGroupId") message_group_id = self._get_param("MessageGroupId")
message_dedupe_id = self._get_param("MessageDeduplicationId") message_dedupe_id = self._get_param("MessageDeduplicationId")

View File

@ -1438,6 +1438,19 @@ def test_send_message_with_delay():
assert len(messages) == 0 assert len(messages) == 0
@mock_aws
def test_send_message_with_message_delay_overriding_queue_delay():
sqs = boto3.client("sqs", region_name="us-east-1")
name = str(uuid4())[0:6]
# By default, all messages on this queue are delayed
resp = sqs.create_queue(QueueName=name, Attributes={"DelaySeconds": "10"})
queue_url = resp["QueueUrl"]
# But this particular message should have no delay
sqs.send_message(QueueUrl=queue_url, MessageBody="test", DelaySeconds=0)
resp = sqs.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10)
assert len(resp["Messages"]) == 1
@mock_aws @mock_aws
def test_send_large_message_fails(): def test_send_large_message_fails():
sqs = boto3.resource("sqs", region_name="us-east-1") sqs = boto3.resource("sqs", region_name="us-east-1")