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

Add support for distributed run #77

Merged
merged 2 commits into from
Oct 7, 2024

Conversation

lmignon
Copy link
Contributor

@lmignon lmignon commented Oct 7, 2024

When tests are distributed, a copy of the database is created for each worker at the start of the test session. This is useful to avoid concurrent access to the same database, which can lead to deadlocks. The provided database is therefore used only as template. At the end of the tests, all the created databases are dropped.

When tests are distributed, a copy of the database is created for each worker at the start of the test session. This is useful to avoid concurrent access to the same database, which can lead to deadlocks. The provided database is therefore used only as template. At the end of the tests, all the created databases are dropped.
@codecov-commenter
Copy link

codecov-commenter commented Oct 7, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 47.36842% with 10 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@b4e05a5). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pytest_odoo.py 47.36% 10 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##             master      #77   +/-   ##
=========================================
  Coverage          ?   33.65%           
=========================================
  Files             ?        1           
  Lines             ?      104           
  Branches          ?        0           
=========================================
  Hits              ?       35           
  Misses            ?       69           
  Partials          ?        0           

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

@lmignon
Copy link
Contributor Author

lmignon commented Oct 7, 2024

ping @yvaucher

Copy link
Contributor

@petrus-v petrus-v left a comment

Choose a reason for hiding this comment

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

Code looks good to me. I Haven't test. I would love to see some kind of unittest but integration test would get more value here which is a bit annoyed to setup so won't lock on that here.

pytest_odoo.py Outdated
Comment on lines 125 to 128
ret = os.system(f"psql -lqt | cut -d \| -f 1 | grep -w {db_name}")
if ret == 0:
os.system(f"dropdb {db_name}")
os.system(f"createdb -T {original_db_name} {db_name}")
Copy link
Contributor

Choose a reason for hiding this comment

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

this sounds a very opinionated way to connect to the database, probably we should at least add such limitation in the Readme file or read odoo config file to retrieves host and credentials informations

Copy link
Member

@yvaucher yvaucher Oct 7, 2024

Choose a reason for hiding this comment

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

You can already configure psql with env var to get to the right config with PGDATABASE, PGUSER, PGHOST and so on. Using psql, dropdb and createdb without params seems fine to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes indeed 👍 !

@yvaucher
Copy link
Member

yvaucher commented Oct 7, 2024

@lmignon should we add a note on pytest-xdist parameter loadscope ?

Did you test it?

It groups tests by class to send related tests to the same worker (thus I would assume on the same DB), it might be a bit for efficient with Savepoints?

https://pytest-xdist.readthedocs.io/en/stable/changelog.html#id189

Copy link
Member

@yvaucher yvaucher left a comment

Choose a reason for hiding this comment

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

Looks great

Code review only need to test that.

pytest_odoo.py Outdated Show resolved Hide resolved
Co-authored-by: Yannick Payot <[email protected]>
@lmignon
Copy link
Contributor Author

lmignon commented Oct 7, 2024

@lmignon should we add a note on pytest-xdist parameter loadscope ?

Did you test it?

It groups tests by class to send related tests to the same worker (thus I would assume on the same DB), it might be a bit for efficient with Savepoints?

https://pytest-xdist.readthedocs.io/en/stable/changelog.html#id189

@yvaucher I've just tested it following your comment. I didn't notice any significant difference between the different ways of distributing tests between workers.

@yvaucher
Copy link
Member

yvaucher commented Oct 7, 2024

Played a bit with it, and works fine, let's merge this. I'll create a small release to make it available.

@yvaucher yvaucher merged commit 6e925f3 into camptocamp:master Oct 7, 2024
6 checks passed
@lmignon lmignon deleted the master-distributed-run branch October 7, 2024 13:29
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.

4 participants