Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cca230a

Browse files
authored
fix change_message_visibility of non-inflight message (localstack#9632)
1 parent 74efe18 commit cca230a

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

‎localstack/services/sqs/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from localstack.aws.api.sqs import (
1515
InvalidAttributeName,
1616
Message,
17-
MessageNotInflight,
1817
QueueAttributeMap,
1918
QueueAttributeName,
2019
ReceiptHandleIsInvalid,
@@ -366,7 +365,7 @@ def update_visibility_timeout(self, receipt_handle: str, visibility_timeout: int
366365
standard_message = self.receipts[receipt_handle]
367366

368367
if standard_message not in self.inflight:
369-
raise MessageNotInflight()
368+
return
370369

371370
standard_message.update_visibility_timeout(visibility_timeout)
372371

‎tests/aws/services/sqs/test_sqs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,21 @@ def test_extend_message_visibility_timeout_set_in_queue(self, sqs_create_queue,
932932
assert messages[0]["Body"] == "test"
933933
assert len(messages) == 1
934934

935+
@markers.aws.validated
936+
def test_change_message_visibility_after_visibility_timeout_expiration(
937+
self, snapshot, sqs_create_queue, aws_client
938+
):
939+
queue_url = sqs_create_queue(Attributes={"VisibilityTimeout": "1"})
940+
aws_client.sqs.send_message(QueueUrl=queue_url, MessageBody="test")
941+
response = aws_client.sqs.receive_message(QueueUrl=queue_url)
942+
receipt = response["Messages"][0]["ReceiptHandle"]
943+
time.sleep(2)
944+
# VisibiltyTimeout was 1 and has now expired
945+
response = aws_client.sqs.change_message_visibility(
946+
QueueUrl=queue_url, ReceiptHandle=receipt, VisibilityTimeout=2
947+
)
948+
snapshot.match("visibility_timeout_expired", response)
949+
935950
@markers.aws.validated
936951
def test_receive_message_with_visibility_timeout_updates_timeout(
937952
self, sqs_create_queue, aws_client

‎tests/aws/services/sqs/test_sqs.snapshot.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,5 +1335,16 @@
13351335
}
13361336
}
13371337
}
1338+
},
1339+
"tests/aws/services/sqs/test_sqs.py::TestSqsProvider::test_change_message_visibility_after_visibility_timeout_expiration": {
1340+
"recorded-date": "14-11-2023, 17:51:55",
1341+
"recorded-content": {
1342+
"visibility_timeout_expired": {
1343+
"ResponseMetadata": {
1344+
"HTTPHeaders": {},
1345+
"HTTPStatusCode": 200
1346+
}
1347+
}
1348+
}
13381349
}
13391350
}

0 commit comments

Comments
 (0)