Commit 71895ae4 authored by Alex Buijs's avatar Alex Buijs

Refactor Labkit::Context to Gitlab::ApplicationContext

From Labkit::Context.with_context
To Gitlab::ApplicationContext.with_base_context
parent ed44219e
......@@ -93,7 +93,7 @@ module Elastic
end
def send_to_processing_queue(job)
Labkit::Context.with_context(job['context']) do
Gitlab::ApplicationContext.with_raw_context(job['context']) do
klass.perform_async(*job['args'])
end
end
......
......@@ -133,7 +133,7 @@ RSpec.describe Elastic::IndexingControlService, :clean_gitlab_redis_shared_state
subject.add_to_waiting_queue!(j, worker_context)
end
expect(Labkit::Context).to receive(:with_context).with(stored_context).exactly(jobs.count).times.and_call_original
expect(Gitlab::ApplicationContext).to receive(:with_raw_context).with(stored_context).exactly(jobs.count).times.and_call_original
expect(worker_class).to receive(:perform_async).exactly(jobs.count).times
expect { subject.resume_processing! }.to change { subject.has_jobs_in_waiting_queue? }.from(true).to(false)
......
......@@ -75,7 +75,7 @@ RSpec.describe Elastic::IndexingControl do
expect_any_instance_of(Gitlab::Elastic::Indexer).not_to receive(:run)
expect(Elastic::IndexingControlService).to receive(:add_to_waiting_queue!).with(worker.class, worker_args, worker_context)
Labkit::Context.with_context(worker_context) do
Gitlab::ApplicationContext.with_raw_context(worker_context) do
worker.perform(*worker_args)
end
end
......
......@@ -27,6 +27,10 @@ module Gitlab
application_context.use(&block)
end
def self.with_raw_context(attributes = {}, &block)
Labkit::Context.with_context(attributes, &block)
end
def self.push(args)
application_context = new(**args)
Labkit::Context.push(application_context.to_lazy_hash)
......
......@@ -900,7 +900,7 @@ RSpec.describe ApplicationController do
feature_category :issue_tracking
def index
Labkit::Context.with_context do |context|
Gitlab::ApplicationContext.with_raw_context do |context|
render json: context.to_h
end
end
......
......@@ -27,6 +27,20 @@ RSpec.describe Gitlab::ApplicationContext do
end
end
describe '.with_raw_context' do
it 'yields the block' do
expect { |b| described_class.with_raw_context({}, &b) }.to yield_control
end
it 'passes the attributes unaltered on to labkit' do
attrs = { foo: :bar }
expect(Labkit::Context).to receive(:with_context).with(attrs)
described_class.with_raw_context(attrs) {}
end
end
describe '.push' do
it 'passes the expected context on to labkit' do
fake_proc = duck_type(:call)
......
......@@ -313,7 +313,7 @@ RSpec.configure do |config|
config.around do |example|
# Wrap each example in it's own context to make sure the contexts don't
# leak
Labkit::Context.with_context { example.run }
Gitlab::ApplicationContext.with_raw_context { example.run }
end
config.around do |example|
......
......@@ -8,7 +8,7 @@ RSpec.shared_examples 'API::CI::Runner application context metadata' do |api_rou
send_request
Labkit::Context.with_context do |context|
Gitlab::ApplicationContext.with_raw_context do |context|
expected_context = {
'meta.caller_id' => api_route,
'meta.user' => job.user.username,
......
......@@ -2,7 +2,7 @@
RSpec.shared_examples 'storing arguments in the application context' do
around do |example|
Labkit::Context.with_context { example.run }
Gitlab::ApplicationContext.with_base_context { example.run }
end
it 'places the expected params in the application context' do
......@@ -12,7 +12,7 @@ RSpec.shared_examples 'storing arguments in the application context' do
subject
Labkit::Context.with_context do |context|
Gitlab::ApplicationContext.with_base_context do |context|
expect(context.to_h)
.to include(log_hash(expected_params))
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