Commit da7ac0e1 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Run sidekiq-server middleware in all specs

Some middlewares are relevant for feature specs.

Mainly: when deduplicating jobs, we want the server middleware to run
to clean up after the client middleware.
parent fff367ce
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'rake_helper' require 'rake_helper'
describe Gitlab::ImportExport::Project::ImportTask do describe Gitlab::ImportExport::Project::ImportTask, :request_store do
let(:username) { 'root' } let(:username) { 'root' }
let(:namespace_path) { username } let(:namespace_path) { username }
let!(:user) { create(:user, username: username) } let!(:user) { create(:user, username: username) }
......
...@@ -299,6 +299,22 @@ RSpec.configure do |config| ...@@ -299,6 +299,22 @@ RSpec.configure do |config|
Labkit::Context.with_context { example.run } Labkit::Context.with_context { example.run }
end end
config.around do |example|
with_sidekiq_server_middleware do |chain|
Gitlab::SidekiqMiddleware.server_configurator(
metrics: false, # The metrics don't go anywhere in tests
arguments_logger: false, # We're not logging the regular messages for inline jobs
memory_killer: false, # This is not a thing we want to do inline in tests
# Don't enable this if the request store is active in the spec itself
# This needs to run within the `request_store` around block defined above
request_store: !RequestStore.active?
).call(chain)
chain.add DisableQueryLimit
example.run
end
end
config.after do config.after do
Fog.unmock! if Fog.mock? Fog.unmock! if Fog.mock?
Gitlab::CurrentSettings.clear_in_memory_application_settings! Gitlab::CurrentSettings.clear_in_memory_application_settings!
......
...@@ -2,6 +2,17 @@ ...@@ -2,6 +2,17 @@
require 'sidekiq/testing' require 'sidekiq/testing'
# rubocop:disable RSpec/ModifySidekiqMiddleware
module SidekiqMiddleware
def with_sidekiq_server_middleware(&block)
Sidekiq::Testing.server_middleware.clear
Sidekiq::Testing.server_middleware(&block)
ensure
Sidekiq::Testing.server_middleware.clear
end
end
# rubocop:enable RSpec/ModifySidekiqMiddleware
# If Sidekiq::Testing.inline! is used, SQL transactions done inside # If Sidekiq::Testing.inline! is used, SQL transactions done inside
# Sidekiq worker are included in the SQL query limit (in a real # Sidekiq worker are included in the SQL query limit (in a real
# deployment sidekiq worker is executed separately). To avoid # deployment sidekiq worker is executed separately). To avoid
...@@ -20,8 +31,3 @@ class DisableQueryLimit ...@@ -20,8 +31,3 @@ class DisableQueryLimit
end end
end end
end end
Sidekiq::Testing.server_middleware do |chain|
chain.add Gitlab::SidekiqStatus::ServerMiddleware
chain.add DisableQueryLimit
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