Commit 711fa6d3 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Isolate the request store for Sidekiq jobs in test

This makes sure that each Sidekiq job has a clean request store to
work with.

Otherwise the values might leak into each other and we'd be counting
Gitaly-calls that would otherwise be isolated incorrectly.
parent bd23039c
......@@ -272,7 +272,7 @@ describe DesignManagement::SaveDesignsService do
expect { run_service }.to change { commit_count.call }.by(1)
end
it 'only does 5 gitaly calls', :request_store, :sidekiq_might_not_need_inline do
it 'only does 4 gitaly calls', :request_store, :sidekiq_might_not_need_inline do
service = described_class.new(project, user, issue: issue, files: files)
# Some unrelated calls that are usually cached or happen only once
service.__send__(:repository).create_if_not_exists
......@@ -281,8 +281,8 @@ describe DesignManagement::SaveDesignsService do
request_count = -> { Gitlab::GitalyClient.get_request_count }
# An exists?, a check for existing blobs, default branch, an after_commit
# callback on LfsObjectsProject, and the creation of commits
expect { service.execute }.to change(&request_count).by(5)
# callback on LfsObjectsProject
expect { service.execute }.to change(&request_count).by(4)
end
context 'when uploading too many files' do
......
......@@ -303,6 +303,7 @@ RSpec.configure do |config|
memory_killer: false # This is not a thing we want to do inline in tests
).call(chain)
chain.add DisableQueryLimit
chain.insert_after ::Gitlab::SidekiqMiddleware::RequestStoreMiddleware, IsolatedRequestStore
example.run
end
......
......@@ -31,3 +31,16 @@ class DisableQueryLimit
end
end
end
# When running `Sidekiq::Testing.inline!` each job is using a request-store.
# This middleware makes sure the values don't leak into eachother.
class IsolatedRequestStore
def call(_worker, msg, queue)
old_store = RequestStore.store.dup
RequestStore.clear!
yield
RequestStore.store = old_store
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