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

ProfileManager: restart daemon in clear_profile #5751

Merged
merged 2 commits into from
Nov 6, 2022

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Nov 6, 2022

No description provided.

When calling `clear_profile` the storage backend will be emptied. If a
daemon is running that is connected to that storage, it may still be
holding references to entities that will now have been removed. As soon
as the daemon will then pick up another process in a later test, it will
hit an exception trying to access the entity in the database that no
longer exists.

To solve this, the `clear_profile` now checks whether the daemon is
running before clearing the storage in which case it stops it. The
daemon is not restarted because this is a costly operation. If there are
many tests that clear the profile but that do not need the daemon, it is
restarted for each test unnecessarily, greatly increasing test run time.
Any test that requires the daemon to be started, should make sure of
that itself.
Shutting down the daemon after every test is costly, especially if many
tests require a daemon and so each test will start and stop the daemon
as opposed to it being shut down once at the end of the session.

The `daemon_client` was initially introduced as being session scoped but
then changed to being function scoped because there was a subtle bug in
that caused the `test_duplicate_subscriber_identifier` to fail. It only
failed though when `test_revive` of `engine/processes/test_control.py`
and `tests/engine/processes/calcjobs/test_calc_job.py` were run before
it.

The problem is that these tests use the `aiida_profile_clean` fixture
which reset the storage backend. However, it doesn't restart the daemon
and it may still hold on to references to entities in the database that
will have been cleaned. The solution is to also restart the daemon if it
was running when resetting the profile. This bug was solved in the
previous commit and so now the original ideal intended scope of the
`daemon_client` fixture can be reinstated.
@sphuber sphuber merged commit aee070f into aiidateam:main Nov 6, 2022
@sphuber sphuber deleted the fix/daemon-client-fixture branch November 6, 2022 12:59
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.

None yet

1 participant