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

Fix file contention issues in parallel tests #2175

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

yaugenst-flex
Copy link
Collaborator

@yaugenst-flex yaugenst-flex commented Jan 17, 2025

This is a follow-up to #2165

Some test were sporadically failing due to I/O contention, so this fixes that. The PR also:

  • Introduces a close_matplotlib fixture that closes all matplotlib figures after testing a module so that these don't hang around for the whole test suite. Gets rid of a few warnings and reduces overall memory consumption.
  • Introduces a reset_logger that reset the logger for each test module, since most modules modify logger state.
  • Changes pytest-xdist distribution algorithm to "worksteal", which brings the time for the whole test suite further down from 160s to 50s (so ~8x improvement in total since Test parallelization #2165). This one should also be significant for CI. Let's see.
  • Removes the duplicate rng fixture in the autograd plugin.

This also includes the change to the test workflow we discussed @daquintero

@yaugenst-flex yaugenst-flex changed the base branch from develop to pre/2.8 January 17, 2025 11:12
Copy link

@yaugenst-flex yaugenst-flex force-pushed the yaugenst-flex/fix-test-race branch from 8760997 to 03c5371 Compare January 17, 2025 12:00
@yaugenst-flex yaugenst-flex self-assigned this Jan 17, 2025
@@ -482,7 +484,9 @@ def test_mode_solver_custom_medium(mock_remote_api, local, tmp_path):
freqs=[freq0],
direction="+",
)
modes = ms.solve() if local else msweb.run(ms)
modes = (
ms.solve() if local else msweb.run(ms, results_file=tmp_path / "ms_custom_medium.hdf5")
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the takehome message here, we shouldn't have multiple tests writing something to the same file? Is it ok if it's across different test files?

Copy link
Collaborator Author

@yaugenst-flex yaugenst-flex Jan 17, 2025

Choose a reason for hiding this comment

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

Not sure whether it's ok across different test files, the problem occurs in tests that write to the same object from multiple workers. I think this is more likely to happen with parameterized tests.

Copy link
Collaborator Author

@yaugenst-flex yaugenst-flex Jan 17, 2025

Choose a reason for hiding this comment

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

What we really need to do is get rid of these global default paths in the tests, I think those are the root cause of the issue, and have each test always use its tmp_path. Currently (some of) the tests end up cluttering the base dir.

Copy link
Collaborator

@daquinteroflex daquinteroflex Jan 21, 2025

Choose a reason for hiding this comment

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

Maybe we can come up with a generic path management solution we can share for the back-end too re test file paths? Something on these lines and we'd just document it in some developers guide.

Copy link
Collaborator Author

@yaugenst-flex yaugenst-flex Jan 21, 2025

Choose a reason for hiding this comment

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

Isn't that what the built-in tmp_path fixture is for? Or do you have something else in mind? I think we just need to do a better job of actually using it 😄

Copy link
Collaborator

@daquinteroflex daquinteroflex left a comment

Choose a reason for hiding this comment

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

Thanks Yannick! This is great.

Mainly I'm thinking should we track this issue of making sure that all our tests paths follow this tmp_path convention both on the frontend and backend? Couldn't seem to find one already. If this can work nicely for the backend path management too. Happy to help on this if we want.

@yaugenst-flex
Copy link
Collaborator Author

yaugenst-flex commented Jan 21, 2025

I am tracking general test refactoring but haven't managed to port this to the new projects tracking, just did not get to that yet. So yeah will tag you too. It's a big project 😄

@yaugenst-flex yaugenst-flex merged commit 3b41c2d into pre/2.8 Jan 21, 2025
15 checks passed
@yaugenst-flex yaugenst-flex deleted the yaugenst-flex/fix-test-race branch January 21, 2025 10:00
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.

3 participants