diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2018-09-03 13:01:34 +0300 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2018-09-04 09:48:00 +0300 |
commit | 39743eaf194b18af622e357ef6bc8edb3db50f10 (patch) | |
tree | 4e110a6e14ba589707b04bc6306727cec72018e0 /spec/support/sidekiq.rb | |
parent | 85b8206c417387c3716ccdc9257bed948f335935 (diff) |
Disable query limit counter in sidekiq
Inside Sidekiq the request is whitelisted to
avoid increasing query counter.
Diffstat (limited to 'spec/support/sidekiq.rb')
-rw-r--r-- | spec/support/sidekiq.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/support/sidekiq.rb b/spec/support/sidekiq.rb index d143014692d..6c4e11910d3 100644 --- a/spec/support/sidekiq.rb +++ b/spec/support/sidekiq.rb @@ -1,7 +1,27 @@ require 'sidekiq/testing/inline' +# If Sidekiq::Testing.inline! is used, SQL transactions done inside +# Sidekiq worker are included in the SQL query limit (in a real +# deployment sidekiq worker is executed separately). To avoid +# increasing SQL limit counter, the request is marked as whitelisted +# during Sidekiq block +class DisableQueryLimit + def call(worker_instance, msg, queue) + transaction = Gitlab::QueryLimiting::Transaction.current + + if !transaction.respond_to?(:whitelisted) || transaction.whitelisted + yield + else + transaction.whitelisted = true + yield + transaction.whitelisted = false + end + end +end + Sidekiq::Testing.server_middleware do |chain| chain.add Gitlab::SidekiqStatus::ServerMiddleware + chain.add DisableQueryLimit end RSpec.configure do |config| |