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

Tests: Only reset database connection at end of suite #5641

Merged
merged 1 commit into from
Sep 22, 2022

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Sep 14, 2022

Fixes #5640

The aiida_profile_clean fixture is a function scoped fixture that provides a fully configured profile with a storage backend that is empty, with the exception of a single default user instance.

To empty the database before the start of the test, it calls the method clear_profile on the TestManager which calls through to the ProfileManager which calls reset_profile on the StorageBackend. However, in addition to resetting the database, it also resets all database connections in the session, which is not really necessary. In addition, it can result in too many clients to the database being active if the session is not cleaned up properly.

We remove the reset_profile call from clear_profile and instead move it to the destroy_all call. This ensures that the database connections are not completely reset in between tests anymore, however, all is nicely cleaned up at the end of the test session.

@chrisjsewell
Copy link
Member

chrisjsewell commented Sep 14, 2022

You should get this to also trigger https://github.com/aiidateam/aiida-core/blob/main/.github/workflows/tests_nightly.sh, i.e. remove skipping certain tests, as obviously we need to make sure this works for the entire test suite

@sphuber
Copy link
Contributor Author

sphuber commented Sep 14, 2022

@chrisjsewell things now seem to work. I just did the minimal changes necessary, but the current interface may be a little clunky. Now rebased #5639 to see if these changes fix the problem there as well.

@sphuber
Copy link
Contributor Author

sphuber commented Sep 20, 2022

@chrisjsewell can you have a look at this one? Just hit the too many clients error again: https://github.com/sphuber/aiida-core/actions/runs/3088574677/jobs/4995218599

EDIT: and another one: https://github.com/aiidateam/aiida-core/actions/runs/3089249073/jobs/4996654548

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

Thanks @sphuber, I'll approve because if the tests work then that's the main thing 👍

(perhaps you could add docstrings to the new Manager methods)

In addition, it can result in too many clients to the database being active if the session is not cleaned up properly.

However, I feel there is still a potential underlying issue here, as to where/why the session is not being cleaned properly

It might be good to at least have a test somewhere (I don't think there is one at present), that checks the session is properly cleaned on profile switching?

@sphuber
Copy link
Contributor Author

sphuber commented Sep 22, 2022

Thanks for the review. I will add the docstrings still, and remove the trigger of the nightly tests. But I will leave adding the profile switching test for another PR, in order to not block this.

The `aiida_profile_clean` fixture is a function scoped fixture that
provides a fully configured profile with a storage backend that is
empty, with the exception of a single default user instance.

To empty the database before the start of the test, it calls the method
`clear_profile` on the `TestManager` which calls through to the
`ProfileManager` which calls `reset_profile` on the `StorageBackend`.
However, in addition to resetting the database, it also resets all
database connections in the session, which is not really necessary. In
addition, it can result in too many clients to the database being active
if the session is not cleaned up properly.

We remove the `reset_profile` call from `clear_profile` and instead move
it to the `destroy_all` call. This ensures that the database connections
are not completely reset in between tests anymore, however, all is
nicely cleaned up at the end of the test session.

Instead of the `reset_profile`, we still call `reset_communicator` and
`reset_runner` as these need to be reset for the next test run to
function properly.
@sphuber sphuber force-pushed the fix/5640/too-many-active-clients branch from 33b913e to 51fe7f0 Compare September 22, 2022 09:30
@sphuber sphuber merged commit 1a223d2 into aiidateam:main Sep 22, 2022
@sphuber sphuber deleted the fix/5640/too-many-active-clients branch September 22, 2022 09:51
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.

Tests randomly fail due to sqlalchemy raising an OperationalError claiming too many clients being active
2 participants