Commit 9d091555 authored by Maxime Orefice's avatar Maxime Orefice Committed by Marius Bobin

Fix database cross-join in ApplicationContext

parent 539197c9
......@@ -124,11 +124,8 @@ module Gitlab
strong_memoize(:runner_project) do
next unless runner&.project_type?
projects = ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/342147') do
runner.projects.take(2) # rubocop: disable CodeReuse/ActiveRecord
end
projects.first if projects.one?
runner_projects = runner.runner_projects.take(2) # rubocop: disable CodeReuse/ActiveRecord
runner_projects.first.project if runner_projects.one?
end
end
......
......@@ -152,6 +152,38 @@ RSpec.describe Gitlab::ApplicationContext do
end
end
end
context 'when using a runner project' do
let_it_be_with_reload(:runner) { create(:ci_runner, :project) }
it 'sets project path from runner project' do
context = described_class.new(runner: runner)
expect(result(context)).to include(project: runner.runner_projects.first.project.full_path)
end
context 'when the runner serves multiple projects' do
before do
create(:ci_runner_project, runner: runner, project: create(:project))
end
it 'does not set project path' do
context = described_class.new(runner: runner)
expect(result(context)).to include(project: nil)
end
end
end
context 'when using an instance runner' do
let_it_be(:runner) { create(:ci_runner, :instance) }
it 'does not sets project path' do
context = described_class.new(runner: runner)
expect(result(context)).to include(project: nil)
end
end
end
describe '#use' do
......
......@@ -833,8 +833,8 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
let(:expected_params) { { project: project.full_path, client_id: "runner/#{runner.id}" } }
end
it_behaves_like 'not executing any extra queries for the application context', 2 do
# Extra queries: Project, Route
it_behaves_like 'not executing any extra queries for the application context', 3 do
# Extra queries: Project, Route, RunnerProject
let(:subject_proc) { proc { request_job } }
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