Skip to content

Skip ActiveJob reloading callback in test env

Thong Kuah requested to merge skip_active_job_callbacks_in_test_env into master

What does this MR do?

Problem

  1. ActiveJob sets up a :around execute callback which ultimately triggers FileUpdateChecker#updated?.
  2. The FileUpdateChecker#updated? can be slow (0.1 to 0.4 seconds), especially with a large glob
  3. For each mail scheduled for delivery (#deliver_later), we trigger this :around execute callback.
  4. It is arguable wether we need code reloading while running specs

Solution

Skip ActiveJob reloading callback in test env

Because we run ActiveJob inline in test env, there is probably no need to have code reloading for this while specs are running. This removes frequent calls to FileUpdateChecker#updated? which is slow on macOS.

This speeds up specs which schedule mailers (mailer #deliver_later uses ActiveJob) by a lot.

Before (master):

$ bundle exec spring rspec spec/services/notification_service_spec.rb 
Running via Spring preloader in process 57985
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
..................................................................................................................................................................................................................................................................................................................................

Finished in 12 minutes 9 seconds (files took 2.81 seconds to load)
322 examples, 0 failures

After:

$ bin/rspec spec/services/notification_service_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
..................................................................................................................................................................................................................................................................................................................................

Finished in 6 minutes 13 seconds (files took 45.77 seconds to load)
322 examples, 0 failures

See also: #241148 detailed analysis, and https://gitlab.com/-/snippets/2010138

Screenshots

This screenshot shows how much time a FileUpdateChecker#updated call can take (1s). Given we call it every time a schedule a mailer (`#deliver_later), this adds up.

Screen_Shot_2020-08-29_at_8.42.09_PM

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Thong Kuah

Merge request reports