[tests:bug] Make running tests atomic to prevent database corruption on failure
Problem
Currently, running the test suite is not atomic. If any test fails during execution, the database can be left in a broken or inconsistent state, which affects further test runs and developer productivity.
Expected behavior
All tests should be isolated in a way that ensures the database remains consistent, regardless of test outcomes. Failed test runs should not leave the database in a broken state.
Suggested solution
- Ensure each test either uses a transactional database setup or is properly cleaned up after execution.
- Consider using fixtures or a setup/teardown process that restores the database state after every test or test suite.
- Investigate test runner options or custom scripts to enforce atomicity for database operations during tests.
Additional context
Making the test suite atomic will make development safer and more reliable for contributors, avoiding hidden issues due to database state leaks between test runs.
One of the few things that I have noticed is
- Running
make runteststwice in a row will lead to the same issue as described in by @nemesifier in #630 and is fixed by #621 - Running selenium tests sometimes causes one of the tests (I am not sure which one) to be stuck, it requires manual refreshing of the page for the test to succeed. If this issue is solved, it will drastically improve the CI as well, because most of the selenium failures are due to this only.
- Running the tests locally on a Linux machine will cause the tests to fail due to missing
/etc/hosts. Will have to check if this is just for Fedora (my os) or every Linux machine #614 test_add_superuserfails if chrome/firefox window is smaller than 500x500 pixels.
I will keep adding more to this list if I find new ones, but the major one is the 2nd one.
@CodingWithSaksham thanks for your analysis, the best thing is to start with some low hanging fruits.