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

Feature: Allow user to specify to not reset boto3-Sessions #7287

Merged

Conversation

bblommers
Copy link
Collaborator

@bblommers bblommers commented Jan 31, 2024

When creating boto3-client for the first time, boto3 will create a default session that caches all kinds of things - including credentials. Subsequent boto3-clients will reuse that Session.

If the first test in your test suite is mocked, the default Session created in that test will have fake credentials, as supplied by Moto. But if the next test is not mocked and should reach out to AWS, it would do so with the mocked credentials from our cached Session.

That is why Moto resets the boto3-Session, to make sure that it is recreated with the correct credentials (either fake or real) everytime. (This was introduced in #2578) It does come at a cost though, as instantiating a new boto3-Session is an expensive operation.

If all of your tests use Moto, and you never want to reach out to AWS, you can choose to not reset the boto3-session. New boto3-clients that are created will reuse the boto3-Session (with fake credentials), making Moto much more performant.

@mock_aws(config={"core": {"reset_boto3_session": False}})

All of our tests are mocked, so it's safe to disable this for every test - but we really don't want to set this value for every single test individually. That's why, as part of this PR, we just override the default config to always set this value to false (in tests/__init__.py).

Test runtime drops from ~30 mins to <15 mins with this change.

@bblommers bblommers added this to the 5.0.1 milestone Jan 31, 2024
@bblommers bblommers force-pushed the feature/config-not-reset-session branch from 4d27cb3 to 7a05006 Compare January 31, 2024 21:14
Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2b2689d) 95.88% compared to head (7a05006) 95.88%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7287   +/-   ##
=======================================
  Coverage   95.88%   95.88%           
=======================================
  Files         843      843           
  Lines       82546    82572   +26     
=======================================
+ Hits        79147    79173   +26     
  Misses       3399     3399           
Flag Coverage Δ
servertests 32.52% <100.00%> (-0.01%) ⬇️
unittests 95.84% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bblommers bblommers merged commit 8cacea9 into getmoto:master Jan 31, 2024
39 checks passed
@bblommers bblommers deleted the feature/config-not-reset-session branch January 31, 2024 22:09
Copy link
Contributor

This is now part of moto >= 5.0.1.dev20

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.

1 participant