HomePhabricator

Clear and reuse database between tests
628d257204baUnpublished

Tags
None
Referenced Files
None
Subscribers
None

Unpublished Commit · Learn More

Publishing Disabled: All publishing is disabled for this repository.

Description

Clear and reuse database between tests

On my system, MariaDB is abysmally slow when altering the database
schema, for reasons I’ve been unable to figure out. Any query creating
or altering a table typically takes several seconds, which makes the
DatabaseStore tests very slow, discouraging me from running them.

This commit improves the tests by reusing the same database within a
test run: instead of completely deleting the database at the end of each
test and setting it up anew in the next one, only delete the rows from
all the tables and do the full setup only once per test run. On my
system, this reduces the runtime from almost five minutes to between 45
seconds and one minute.

This uses DELETE FROM instead of TRUNCATE TABLE because TRUNCATE TABLE
is really just a DROP TABLE + CREATE TABLE in disguise, so on my system
it’s only slightly faster than the full reinitialization (running for
some three and a half minutes instead of almost five). On installations
that are properly set up (e. g. in CI), TRUNCATE TABLE would likely be
faster than DELETE FROM, but the tables should be small enough that I
don’t expect it to matter much.

For a similar reason, we skip resetting the AUTO_INCREMENT counter –
according to a comment on StackOverflow [1], this also ends up
re-creating the table.

[1]: https://stackoverflow.com/questions/8923114/how-to-reset-auto-increment-in-mysql/8923132#comment27561210_8923132

Details

Provenance
LucasWerkmeisterAuthored on Apr 6 2019, 11:32 AM
Parents
R2494:0ad285bf52a4: Change DatabaseStore tests to use fixture
Branches
Unknown
Tags
Unknown
ChangeId
None