tempest-framework icon indicating copy to clipboard operation
tempest-framework copied to clipboard

database rollback support for the testsuite

Open Treggats opened this issue 1 year ago • 5 comments

Description We've added support for multiple database dialects. However, this CI still only runs on SQLite. Which is fine at first, but if we want to fully support multiple database dialects then we need to use them in the CI as well.

Setting up the CI to use those can be done pretty easily, but the testsuite at the moment isn't ready for this.

The issue When running tests with SQLite I believe that the database is fully destroyed and created again. This is, however, not the case for the other dialects. With which we run into test failures, because the table it is trying to create already exists from a previous test.

Treggats avatar Aug 16 '24 11:08 Treggats

Why don't we spin up an individual action using a matrix? That way we always start from a clean slate?

brendt avatar Aug 16 '24 11:08 brendt

The different databases aren't the issue. Use the MySQL driver for the tests are run the testsuite. That bests demonstrates the issue

Treggats avatar Aug 16 '24 11:08 Treggats

With FrameworkIntegrationTestCase, the SQLite database is deleted and re-copied every test run. Nothing is currently happening with other dialects like Laravel supports with the RefreshDatasebase trait.

I think our default stance should be to not refresh the database on every test case, as that will impact performance. Obviously we do need to support this though, since you will need to do it for tests around migrations, etc.

This probably goes hand-in-hand with a refactor of the test helpers.

aidan-casey avatar Aug 16 '24 12:08 aidan-casey

I think our default stance should be to not refresh the database on every test case

I agree, only on the parts where the tables are being recreated. what data is stored inside them is of less concern I gather

Treggats avatar Aug 16 '24 12:08 Treggats

Gotcha! Ok let's take this into account for alpha2 :)

Edit: I guess it's pretty important for the multi-database setup, so let's do it now. I agree with Aidan that no rollback would be preferable, but we'd probably need to rewrite our tests (because we migrate in every one of them). We could work around that by changing the FrameworkIntegrationTest::migrate function, so that it keeps track of migrations, but still, I think it'll lead to a lot of edge cases.

The first step would be to have a complete rollback, and then figure out how to improve it from there.

brendt avatar Aug 16 '24 17:08 brendt

I'm gonna look into this

brendt avatar Aug 28 '24 11:08 brendt

Rollback in itself works, although there are still several errors on MySQL and Postgres. Gonna make a new issue for it

brendt avatar Aug 28 '24 12:08 brendt