10000 use snapshots for SNS tests by bentsku · Pull Request #6601 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

use snapshots for SNS tests #6601

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 5 commits into from
Aug 9, 2022
Merged

use snapshots for SNS tests #6601

merged 5 commits into from
Aug 9, 2022

Conversation

bentsku
Copy link
Contributor
@bentsku bentsku commented Aug 5, 2022

This PR adds the use of snapshots for every aws_validated test in the SNS test suite, following #6586
We skip some paths for now to be fixed in a later iteration. It is mostly fields not added (or added when it should not be) by Moto.
Also, it seems AWS doesn't add message signature for Fifo topics, so we will need to remove those fields.
I added some exception messages fixes as well.

It contains a hacky fix that will be added in #6598 and will be removed then in order to guarantee the order of the fields.

@bentsku bentsku requested review from thrau and steffyP August 5, 2022 15:49
@bentsku bentsku temporarily deployed to localstack-ext-tests August 5, 2022 15:49 Inactive
@github-actions
Copy link
github-actions bot commented Aug 5, 2022

LocalStack integration with Pro

       3 files         3 suites   1h 7m 32s ⏱️
1 177 tests 1 135 ✔️ 42 💤 0
1 542 runs  1 469 ✔️ 73 💤 0

Results for commit 0883522.

♻️ This comment has been updated with latest results.

@bentsku bentsku temporarily deployed to localstack-ext-tests August 5, 2022 21:44 Inactive
@coveralls
Copy link
coveralls commented Aug 5, 2022

Coverage Status

Coverage decreased (-0.02%) to 91.608% when pulling ee257ab on snapshot-sns-tests into 5c77d19 on master.

Copy link
Member
@thrau thrau left a comment

Choose a reason for hiding this comment

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

Looks fantastic, snapshots allover 📸 ✨

I'll let @dominikschubert and @steffyP comment/decide on the changes in the transformer utils.

Comment on lines 169 to 171
TransformerUtility.key_value(
"SenderId", value_replacement="111111111111", reference_replacement=False
),
Copy link
Member

Choose a reason for hiding this comment

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

I had a similar issue in #6603. It seems related to the the fact that the SenderId of an SQS message can sometimes be the root account ID, and sometimes the access key id, see. https://stackoverflow.com/a/28603793/804840
This then messes up the comparisons.

Any idea what a good pattern is for this @steffyP @dominikschubert ?

Copy link
Member

Choose a reason for hiding this comment

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

@thrau: Interesting :) I think a key-value replacement should be fine in that case. We could also include a regex-check to make sure it matches one of the two valid patterns. but seems like a overhead in that case.

Only thing that feels a bit hacky here: if we replace it with 1s, one could assume that the region-regex-replacement was used here - which is not the case. @bentsku is there a particular reason why you have chosen this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TransformerUtility.key_value(
"Signature", value_replacement="<signature>", reference_replacement=False
),
TransformerUtility.key_value("MD5OfBody", "<md5-hash>", reference_replacement=False),
Copy link
Member

Choose a reason for hiding this comment

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

should we not maybe leave this in per default? or are you having issues with bodies containing data that is dynamically generated by the tests? (like passing ARNs through a message body).

Copy link
Member

Choose a reason for hiding this comment

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

+1
If the md5 hash matches in most cases, we should not always exclude it. Is this the case for SNS?
Ideally we would only exclude md5-hashes for individual test cases with a note why it has to be replaced (e.g. includes timestamp).

Copy link
Contributor Author
@bentsku bentsku Aug 8, 2022

Choose a reason for hiding this comment

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

The MD5 hash almost never matches: the body of the SNS message always contains a timestamp, and a signature.
It only matches when RawDelivery is set to True, as the body is the string message passed. I had to manually add the MD5 transformer to almost every test. I thought the MD5 hash could just be checked with a unit test.
Otherwise, I had an over engineered way to do, which was to delete the MD5 transformer from the sns_api with a fixture that I would add to the test.
What do you think we should do in this case?

Copy link
Member

Choose a reason for hiding this comment

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

alright :) i think in that case, having unittests should be fine.
alternatively we could also create another api-helper, which excludes the md5-transformer and use this one for the RawDelivery messages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it could work as well. The issue also that I didn't think about is that in some tests, we have both RawDelivery and regular in the same test. So I have to ignore the hash. Maybe I will manually check the MD5 of raw messages in the integration tests? As it's AWS validated, it will check the behaviour when we regenerate the snapshots

Copy link
Member

Choose a reason for hiding this comment

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

I see :) yes, sounds good. but I think it would also be fine to cover the md5-checksum in unittests as you suggested before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The md5 is part of SQS, and is covered inside the integration tests there, there shouldn't be any regression on that side.

Comment on lines +183 to +191
TransformerUtility.key_value(
"Signature", value_replacement="<signature>", reference_replacement=False
),
Copy link
Member

Choose a reason for hiding this comment

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

should we maybe just use the default value_replacement?

Copy link
Member

Choose a reason for hiding this comment

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

with the reference_replacement set to false, the default value would be signature. I think it's fine to use <signature> here as it indicates at the first sight that the value was replaced.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that was my issue, the fact that the <[...]> were missing was troubling me, so I added it manually!

Copy link
Member
@steffyP steffyP left a comment

Choose a reason for hiding this comment

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

Nice to see so many snapshot tests 😄 📸 😍

Only one thing that bothers me a bit: the SenderId replacement somehow shadows the regex accountid replacement. Maybe we can improve this?

Regarding the snapshot-PR you are depending on: I am waiting for a review from @dominikschubert and his input :)

TransformerUtility.key_value("SenderId"),
# account ID
TransformerUtility.key_value(
"SenderId", value_replacement="111111111111", reference_replacement=False
Copy link
Member

Choose a reason for hiding this comment

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

@bentsku: is there a specific reason why you decided to replace the senderId with 1s? IMO it can be a bit misleading, as we also have the regex-replacement for the account-id, and on first sight it will look like the regex-replacement is responsible for this replacement.

Personally, I would prefer if we could use distinct replacements values for transformers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going to test it again, but I believe the issue was that locally, the SenderId was replaced by 1s, and not in the tests against AWS. I'll check again, could be priorities, I need to check what the response was before transformation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now changed and simply use reference_replacement=False instead, as it is enough to not mess with ARN anymore

@bentsku bentsku temporarily deployed to localstack-ext-tests August 8, 2022 15:37 Inactive
@bentsku
Copy link
Contributor Author
bentsku commented Aug 8, 2022

Thanks a lot for your reviews, I updated the PR with your comments.
We should not merge until #6598 is merged, I'm worried the ordering could break the tests as I am using it only partially in my branch. I will rebase on master once it is done and regenerate the tests that fails, if they do.
Thanks again!

@bentsku bentsku temporarily deployed to localstack-ext-tests August 8, 2022 15:49 Inactive
@bentsku bentsku force-pushed the snapshot-sns-tests branch from ee257ab to 25913f1 Compare August 9, 2022 09:41
@bentsku bentsku temporarily deployed to localstack-ext-tests August 9, 2022 09:41 Inactive
@bentsku bentsku requested a review from F438 steffyP August 9, 2022 09:42
@bentsku bentsku force-pushed the snapshot-sns-tests branch from 25913f1 to 0883522 Compare August 9, 2022 10:25
@bentsku bentsku temporarily deployed to localstack-ext-tests August 9, 2022 10:25 Inactive
Copy link
Member
@steffyP steffyP left a comment

Choose a reason for hiding this comment

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

LGTM! thanks for cleaning up the tests and for your help with improving the snapshot transformers 🚀 👍

@bentsku bentsku merged commit 3f7a7fe into master Aug 9, 2022
@bentsku bentsku deleted the snapshot-sns-tests branch August 9, 2022 11:48
@localstack localstack locked and limited conversation to collaborators Aug 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0