Commit 420b461c authored by Thong Kuah's avatar Thong Kuah

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 FileUpdateCheker#updated? which is slow on macOS.
parent 97865775
# frozen_string_literal: true
return unless Rails.env.test?
Rails.application.configure do
config.after_initialize do
# We don't care about ActiveJob reloading the code in test env as we run
# jobs inline in test env.
# So in test, we remove this callback, which calls app.reloader.wrap, and
# ultimately calls FileUpdateChecker#updated? which is slow on macOS
#
# https://github.com/rails/rails/blob/6-0-stable/activejob/lib/active_job/railtie.rb#L39-L46
def active_job_railtie_callback?
callbacks = ActiveJob::Callbacks.singleton_class.__callbacks[:execute]
callbacks &&
callbacks.send(:chain).size == 1 &&
callbacks.first.kind == :around &&
callbacks.first.raw_filter.is_a?(Proc) &&
callbacks.first.raw_filter.source_location.first.ends_with?('lib/active_job/railtie.rb')
end
if active_job_railtie_callback?
ActiveJob::Callbacks.singleton_class.reset_callbacks(:execute)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'ActiveJob execute callback' do
it 'is removed in test environment' do
expect(ActiveJob::Callbacks.singleton_class.__callbacks[:execute].send(:chain).size).to eq(0)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment