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

Dont list buckets in s3 tests #318

Merged
merged 3 commits into from
May 29, 2019

Conversation

caboteria
Copy link
Contributor

While working on a previous PR I stubbed my toe on AWS permissions. The tests needed to be able to list all of the bucket names in my account but I'm not comfortable giving those permissions to Travis so I modified the cleanup_bucket() method to directly delete the bucket instead of listing each bucket to decide whether to delete it or not.

After I made that change I noticed that I was getting more test failures due to race conditions - tests expecting the test bucket to be there when it wasn't or vice versa. To make this happen less often I changed the suite so it creates the test bucket before the tests run and deletes it afterward instead of create/delete per test. This is more stable and saves 20-30s in the s3 tests when running without mocks.

toby cabot added 2 commits May 20, 2019 11:16
The tests used a ListBuckets operation which requires privileges that
I'm not comfortable giving to Travis, and which aren't actually
necessary.  We know what the bucket name is so we don't need to scan
each and every bucket, we can just open the one we want.

Also removed an if/then on test bucket creation which caused race
conditions.
The s3 tests were deleting and creating the same bucket over and over
which isn't necessary - we now create the bucket once before the tests
run and delete it after they're done.  This is a little faster and
appears to reduce the number of race conditions that we hit.
@mpenkov
Copy link
Collaborator

mpenkov commented May 21, 2019

The tests needed to be able to list all of the bucket names in my account but I'm not comfortable giving those permissions to Travis so I modified the cleanup_bucket() method to directly delete the bucket instead of listing each bucket to decide whether to delete it or not.

You shouldn't have to give any of your credentials to travis. My understanding is that it uses our credentials, specified in the env.global.secure section in the .travis.yml file. Could you please confirm?

Copy link
Collaborator

@mpenkov mpenkov left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. Left you some comments.

smart_open/tests/test_s3.py Outdated Show resolved Hide resolved
smart_open/tests/test_s3.py Outdated Show resolved Hide resolved
smart_open/tests/test_s3.py Show resolved Hide resolved
smart_open/tests/test_s3.py Show resolved Hide resolved
@caboteria
Copy link
Contributor Author

You shouldn't have to give any of your credentials to travis. My understanding is that it uses our credentials, specified in the env.global.secure section in the .travis.yml file. Could you please confirm?

This is true only when the tests run in the context of the Travis RaRe-Technologies/smart_open project. Each project has its own unique private/public key pair. I wanted to be able to trigger builds of my fork so I set up a Travis project for my fork so the private key is different. I can write a wiki page explaining how to do that if you'd like, it's not hard once you figure out what permissions are needed.

piskvorky#318 (review)

 - No more global "s3" handle - allocate one locally when needed

 - Document setUpModule and tearDownModule

 - Document when we create/delete the test bucket

 - Put populate_bucket back where it was

 - Call cleanup_bucket after each test
@caboteria
Copy link
Contributor Author

I think I did all of the things you asked for but let me know if I missed something.

caboteria pushed a commit to Affectiva/smart_open that referenced this pull request May 21, 2019
piskvorky#318 (review)

 - No more global "s3" handle - allocate one locally when needed

 - Document setUpModule and tearDownModule

 - Document when we create/delete the test bucket

 - Put populate_bucket back where it was

 - Call cleanup_bucket after each test
@mpenkov mpenkov merged commit 86964ad into piskvorky:master May 29, 2019
@mpenkov
Copy link
Collaborator

mpenkov commented May 29, 2019

Great work. Thank you for your contribution!

@mpenkov mpenkov mentioned this pull request May 31, 2019
mpenkov added a commit that referenced this pull request May 31, 2019
Two separate PRs were touching the same code. [1] modified the bucket
handling to perform it at module load time. In the meanwhile, [2] fixed
a broken test by relying on functionality that wasn't around after [1]
got merged.

[1] #318
[2] #322
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants