Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqs: Clear depduplication cache when FifoQueue is cleared #8218

Merged
merged 7 commits into from May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions localstack/services/sqs/models.py
Expand Up @@ -983,6 +983,7 @@ def clear(self):
self.message_groups.clear()
self.inflight_groups.clear()
self.message_group_queue.queue.clear()
self.deduplication.clear()


class SqsStore(BaseStore):
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/test_sqs.py
Expand Up @@ -2924,6 +2924,36 @@ def test_purge_queue_deletes_delayed_messages(self, sqs_create_queue, aws_client
receive_result = aws_client.sqs.receive_message(QueueUrl=queue_url, WaitTimeSeconds=1)
assert "Messages" not in receive_result.keys()

@pytest.mark.aws_validated
def test_purge_queue_clears_fifo_deduplication_cache(self, sqs_create_queue, aws_client):
fifo_queue_name = f"test-queue-{short_uid()}.fifo"
queue_url = sqs_create_queue(QueueName=fifo_queue_name, Attributes={"FifoQueue": "true"})
dedup_id = f"fifo_dedup-{short_uid()}"
group_id = f"fifo_group-{short_uid()}"

aws_client.sqs.send_message(
QueueUrl=queue_url,
MessageBody="message-1",
MessageGroupId=group_id,
MessageDeduplicationId=dedup_id,
)

aws_client.sqs.purge_queue(QueueUrl=queue_url)

aws_client.sqs.send_message(
Comment on lines +2934 to +2943
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original reproduction template of your issue #8211 there was an additional step here before the purge (a receive message call) - is this necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't necessary. The issue reproduction step was just to illustrate that the message was pushed previously & could be retrieved. That is covered by other tests.

QueueUrl=queue_url,
MessageBody="message-2",
MessageGroupId=group_id,
MessageDeduplicationId=dedup_id,
)

receive_result = aws_client.sqs.receive_message(QueueUrl=queue_url, WaitTimeSeconds=1)

assert len(receive_result["Messages"]) == 1
message = receive_result["Messages"][0]

assert message["Body"] == "message-2"

@pytest.mark.aws_validated
@pytest.mark.skip_snapshot_verify(paths=["$..Error.Detail"])
def test_successive_purge_calls_fail(self, sqs_create_queue, monkeypatch, snapshot, aws_client):
Expand Down