Commit 5989e502 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'skip_active_job_callbacks_in_test_env' into 'master'

Skip ActiveJob reloading callback in test env

See merge request gitlab-org/gitlab!40840
parents 670db777 420b461c
# 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