Why is the database truncated when using test parallalization?

This one really caught me off guard:

https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/activerecord/lib/active_record/tasks/database_tasks.rb#L404-L420

I run an unusual database structure, but I think this would catch standard users off guard too.

With the default config for tests in Rails 6.1:

parallelize(workers: :number_of_processors)

the database gets truncated just before the tests run. This seems to have been put in place to support the new, more complicated database structure support.

In my case, I’m seeding a bunch of data into the database and this just wipes it out.

I was wondering what the purpose was for this and if there’s a way to work around it other than disabling the parallel testing feature?

The change seems to have come in here:

https://github.com/rails/rails/commit/d8b817134391b497eb6fa0a9dd2790157812411d

@jhawthorn

Oh I get it! The parallelisation creates copies of the database with a numerical suffix:

https://github.com/rails/rails/commit/26821d9b572815a39c8ecb2e19375b2abff68730

This completely won’t work with my setup so it makes sense to not use this feature.

Took a while to join all the dots lol :slight_smile: :grin: