-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix SQS queue creation attributes and specific attribute retrieval #2005
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| import json | ||
| import unittest | ||
|
|
||
| from localstack.utils import testutil | ||
| from localstack.utils.aws import aws_stack | ||
| from localstack.utils.common import short_uid, load_file, retry | ||
| from .test_lambda import TEST_LAMBDA_PYTHON, LAMBDA_RUNTIME_PYTHON36, TEST_LAMBDA_LIBS | ||
| from .lambdas import lambda_integration | ||
| from .test_lambda import TEST_LAMBDA_PYTHON, LAMBDA_RUNTIME_PYTHON36, TEST_LAMBDA_LIBS | ||
|
|
||
| TEST_QUEUE_NAME = 'TestQueue' | ||
|
|
||
|
|
@@ -70,7 +71,7 @@ def test_publish_get_delete_message(self): | |
| response = self.client.receive_message(QueueUrl=queue_url) | ||
| self.assertFalse(response.get('Messages')) | ||
| self.client.change_message_visibility(QueueUrl=queue_url, | ||
| ReceiptHandle=messages[0]['ReceiptHandle'], VisibilityTimeout=0) | ||
| ReceiptHandle=messages[0]['ReceiptHandle'], VisibilityTimeout=0) | ||
| for i in range(2): | ||
| messages = self.client.receive_message(QueueUrl=queue_url, VisibilityTimeout=0)['Messages'] | ||
| self.assertEquals(len(messages), 1) | ||
|
|
@@ -116,7 +117,7 @@ def test_send_message_attributes(self): | |
| payload = {} | ||
| attrs = {'attr1': {'StringValue': 'val1', 'DataType': 'String'}} | ||
| self.client.send_message(QueueUrl=queue_url, MessageBody=json.dumps(payload), | ||
| MessageAttributes=attrs) | ||
| MessageAttributes=attrs) | ||
|
|
||
| result = self.client.receive_message(QueueUrl=queue_url, MessageAttributeNames=['All']) | ||
| messages = result['Messages'] | ||
|
|
@@ -149,15 +150,16 @@ def test_dead_letter_queue_execution(self): | |
| queue_arn1 = aws_stack.sqs_queue_arn(queue_name1) | ||
| policy = {'deadLetterTargetArn': queue_arn1, 'maxReceiveCount': 1} | ||
| queue_url2 = self.client.create_queue(QueueName=queue_name2, | ||
| Attributes={'RedrivePolicy': json.dumps(policy)})['QueueUrl'] | ||
| Attributes={'RedrivePolicy': json.dumps(policy)})['QueueUrl'] | ||
| queue_arn2 = aws_stack.sqs_queue_arn(queue_name2) | ||
|
|
||
| # create Lambda and add source mapping | ||
| lambda_name = 'test-%s' % short_uid() | ||
| zip_file = testutil.create_lambda_archive(load_file(TEST_LAMBDA_PYTHON), | ||
| get_content=True, libs=TEST_LAMBDA_LIBS, runtime=LAMBDA_RUNTIME_PYTHON36) | ||
| get_content=True, libs=TEST_LAMBDA_LIBS, | ||
| runtime=LAMBDA_RUNTIME_PYTHON36) | ||
| testutil.create_lambda_function(func_name=lambda_name, zip_file=zip_file, | ||
| runtime=LAMBDA_RUNTIME_PYTHON36) | ||
| runtime=LAMBDA_RUNTIME_PYTHON36) | ||
| lambda_client.create_event_source_mapping(EventSourceArn=queue_arn2, FunctionName=lambda_name) | ||
|
|
||
| # add message to SQS, which will trigger the Lambda, resulting in an error | ||
|
|
@@ -174,4 +176,46 @@ def receive_dlq(): | |
| self.assertIn('RequestID', msg_attrs) | ||
| self.assertIn('ErrorCode', msg_attrs) | ||
| self.assertIn('ErrorMessage', msg_attrs) | ||
|
|
||
| retry(receive_dlq, retries=8, sleep=2) | ||
|
|
||
| def test_set_queue_attribute_at_creation(self): | ||
| queue_name = 'queue-%s' % short_uid() | ||
|
|
||
| attributes = { | ||
| 'MessageRetentionPeriod': '604800', # This one is unsupported by ElasticMq and should be saved in memory | ||
| 'ReceiveMessageWaitTimeSeconds': '10', | ||
| 'VisibilityTimeout': '30' | ||
| } | ||
|
|
||
| queue_url = self.client.create_queue(QueueName=queue_name, Attributes=attributes)['QueueUrl'] | ||
| creation_attributes = self.client.get_queue_attributes(QueueUrl=queue_url, AttributeNames=['All']) | ||
|
|
||
| # assertion | ||
| self.assertIn('MessageRetentionPeriod', creation_attributes['Attributes'].keys()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: We could also assert that the correct value is returned here ( |
||
| self.assertEqual('604800', creation_attributes['Attributes']['MessageRetentionPeriod']) | ||
|
|
||
| # cleanup | ||
| self.client.delete_queue(QueueUrl=queue_url) | ||
|
|
||
| def test_get_specific_queue_attribute_response(self): | ||
| queue_name = 'queue-%s' % short_uid() | ||
|
|
||
| # Two attributes unsupported by ElasticMq | ||
| attributes = { | ||
| 'MessageRetentionPeriod': '604800', | ||
| 'DelaySeconds': '10', | ||
| } | ||
|
|
||
| queue_url = self.client.create_queue(QueueName=queue_name, Attributes=attributes)['QueueUrl'] | ||
| unsupported_attribute_get = self.client.get_queue_attributes(QueueUrl=queue_url, | ||
| AttributeNames=['MessageRetentionPeriod']) | ||
| supported_attribute_get = self.client.get_queue_attributes(QueueUrl=queue_url, | ||
| AttributeNames=['QueueArn']) | ||
| # assertion | ||
| self.assertTrue('MessageRetentionPeriod' in unsupported_attribute_get['Attributes'].keys()) | ||
| self.assertEqual('604800', unsupported_attribute_get['Attributes']['MessageRetentionPeriod']) | ||
| self.assertTrue('QueueArn' in supported_attribute_get['Attributes'].keys()) | ||
|
|
||
| # cleanup | ||
| self.client.delete_queue(QueueUrl=queue_url) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming we're accessing index
0here becausereq_datais created fromurlparsewhich creates values as lists. We should probably update the documentation comment of this method then:... 'AttributeName.1': ['Policy'] ....In the future, we may apply some small preprocessing to extract all values from the lists contained in
req_data, as usually they only contain a single item anyway.