The problem with parallel hooks
Previously, developers had the ability to append their own hooks to parallel tests, but there was no straightforward way to bypass the Rails database parallelization hooks. This limitation could be restrictive in cases where developers wanted to implement their own database handling processes.
Skipping database hooks
The core of this change lies in the introduction of a new configuration option that allows developers to skip Rails database parallelization. By setting the parallelize_databases
parameter to false
in the parallelize
caller or configuring config.active_support.parallelize_test_databases
to false
in the application config, developers can now control whether Rails creates databases for each process during parallel testing.
Here's how that would look like:
class ActiveSupport::TestCase
parallelize(workers: 10, parallelize_databases: false)
end
It's worth noting that this configuration is set to true
by default, ensuring backward compatibility for existing projects. However, developers now have the freedom to customize this behavior based on their specific requirements. It's also important to mention potential deadlocks that may occur if databases are not created for each process.