Testing speed: ActiveRecord use_transactional_fixtures vs DatabaseCleaner.strategy =: transaction

Judging by the source ( database_cleaner , active_record ), it looks like they should be equally fast. But there are allegations that using the database_cleaner transactional strategy slows down the characteristics of the controller and model ( for example ). I do not have a large set of tests in my hand for benchmarking. Does anyone know or compare these two?

+7
source share
1 answer

I spent a bit of time comparing the two based on mid-sized code that uses ActiveRecord tools extensively. When I switched it to using DatabaseCleaner instead of use_transactional_fixtures , the model specifications began to take about twice as much time.

After you did the same comparison, I realized that there are two things that use_transactional_fixtures :

  • Regardless of whether each specification is enclosed in a transaction
  • In this process, instrument data is loaded using ActiveRecord.
    • When use_transactional_fixtures true, device data is downloaded once, before the first test
    • When it is false, binding data is loaded before each specification

DatabaseCleaner transaction strategy can replace (1). But the disadvantage is that your package will reload the same device data.

So, if you do not use AR devices (or use only a couple), the transaction strategies use_transactional_fixtures and DatabaseCleaner will have similar performance. But if you use a large number of AR fittings, then disabling use_transactional_fixtures will have a big impact on performance.

+9
source

All Articles