Repository: localstack/localstack

Issue:
SQS: ChangeMessageVisibility not working
Using the most recent version of LocalStack and the most recent version of the AWS CLI...

```
awslocal sqs create-queue --queue-name foo                                                                                                                                                                         
{                                                                                                                                                                                                                  
    "QueueUrl": "http://localhost:4566/000000000000/foo"
} 

awslocal sqs send-message --message-body hello --queue-url http://localhost/000000000000/foo                                                                                                                       
{                                                                                                                                                                                                                  
  "MD5OfMessageBody": "5d41402abc4b2a76b9719d911017c592", 
  "MessageId": "53be5840-770a-49e6-8e23-cfca3469c7ff" 
}
                                                                                                                                                                                                                                                                                                              
awslocal sqs receive-message --queue-url http://localhost/000000000000/foo
{
   "Messages": [                                                                                                                                                                                                  
        {                                                                                                                                                                                                          
            "MessageId": "53be5840-770a-49e6-8e23-cfca3469c7ff",                                                                                                                                                   
            "ReceiptHandle": "ZmE3NTAxZjItZTEzMS00ZDNjLWE0ODgtODUzNTU0ZjE4YzBjIGFybjphd3M6c3FzOnVzLWVhc3QtMTowMDAwMDAwMDAwMDA6Zm9vIDUzYmU1ODQwLTc3MGEtNDllNi04ZTIzLWNmY2EzNDY5YzdmZiAxNjk4OTUwNjM2LjQxODc3ODc=",   
            "MD5OfBody": "5d41402abc4b2a76b9719d911017c592",                                                                                                                                                       
            "Body": "hello"                                                                                                                                                                                        
        }                                                                                                                                                                                                          
    ]                                                                                                                                                                                                              
}                                                                                                                                                                                                                  

awslocal sqs change-message-visibility --visibility-timeout 10 --queue-url http://localhost:4566/000000000000/foo --receipt-handle ZmE3NTAxZjItZTEzMS00ZDNjLWE0ODgtODUzNTU0ZjE4YzBjIGFybjphd3M6c3FzOnVzLWVhc3QtMTo\wMDAwMDAwMDAwMDA6Zm9vIDUzYmU1ODQwLTc3MGEtNDllNi04ZTIzLWNmY2EzNDY5YzdmZiAxNjk4OTUwNjM2LjQxODc3ODc=                                                                                                                  
                                                                                                                                                                                                                   
An error occurred (AWS.SimpleQueueService.MessageNotInflight) when calling the ChangeMessageVisibility operation: Unknown 
```


Discussion:

Resolving patch:
diff --git a/localstack/services/sqs/models.py b/localstack/services/sqs/models.py
--- a/localstack/services/sqs/models.py
+++ b/localstack/services/sqs/models.py
@@ -14,7 +14,6 @@
 from localstack.aws.api.sqs import (
     InvalidAttributeName,
     Message,
-    MessageNotInflight,
     QueueAttributeMap,
     QueueAttributeName,
     ReceiptHandleIsInvalid,
@@ -366,7 +365,7 @@ def update_visibility_timeout(self, receipt_handle: str, visibility_timeout: int
             standard_message = self.receipts[receipt_handle]
 
             if standard_message not in self.inflight:
-                raise MessageNotInflight()
+                return
 
             standard_message.update_visibility_timeout(visibility_timeout)
 


Test patch:
diff --git a/tests/aws/services/sqs/test_sqs.py b/tests/aws/services/sqs/test_sqs.py
--- a/tests/aws/services/sqs/test_sqs.py
+++ b/tests/aws/services/sqs/test_sqs.py
@@ -932,6 +932,21 @@ def test_extend_message_visibility_timeout_set_in_queue(self, sqs_create_queue,
         assert messages[0]["Body"] == "test"
         assert len(messages) == 1
 
+    @markers.aws.validated
+    def test_change_message_visibility_after_visibility_timeout_expiration(
+        self, snapshot, sqs_create_queue, aws_client
+    ):
+        queue_url = sqs_create_queue(Attributes={"VisibilityTimeout": "1"})
+        aws_client.sqs.send_message(QueueUrl=queue_url, MessageBody="test")
+        response = aws_client.sqs.receive_message(QueueUrl=queue_url)
+        receipt = response["Messages"][0]["ReceiptHandle"]
+        time.sleep(2)
+        # VisibiltyTimeout was 1 and has now expired
+        response = aws_client.sqs.change_message_visibility(
+            QueueUrl=queue_url, ReceiptHandle=receipt, VisibilityTimeout=2
+        )
+        snapshot.match("visibility_timeout_expired", response)
+
     @markers.aws.validated
     def test_receive_message_with_visibility_timeout_updates_timeout(
         self, sqs_create_queue, aws_client
diff --git a/tests/aws/services/sqs/test_sqs.snapshot.json b/tests/aws/services/sqs/test_sqs.snapshot.json
--- a/tests/aws/services/sqs/test_sqs.snapshot.json
+++ b/tests/aws/services/sqs/test_sqs.snapshot.json
@@ -1335,5 +1335,16 @@
         }
       }
     }
+  },
+  "tests/aws/services/sqs/test_sqs.py::TestSqsProvider::test_change_message_visibility_after_visibility_timeout_expiration": {
+    "recorded-date": "14-11-2023, 17:51:55",
+    "recorded-content": {
+      "visibility_timeout_expired": {
+        "ResponseMetadata": {
+          "HTTPHeaders": {},
+          "HTTPStatusCode": 200
+        }
+      }
+    }
   }
 }