2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-15 06:16:12 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Admin::RunnersController do
|
2020-01-24 07:09:01 -05:00
|
|
|
let_it_be(:runner) { create(:ci_runner) }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(create(:admin))
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
2019-02-26 14:30:43 -05:00
|
|
|
render_views
|
|
|
|
|
2017-02-15 06:16:12 -05:00
|
|
|
it 'lists all runners' do
|
|
|
|
get :index
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
2019-02-26 14:30:43 -05:00
|
|
|
|
|
|
|
it 'avoids N+1 queries', :request_store do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new { get :index }.count
|
|
|
|
|
2019-06-25 13:54:42 -04:00
|
|
|
create_list(:ci_runner, 5, :tagged_only)
|
2019-02-26 14:30:43 -05:00
|
|
|
|
|
|
|
# There is still an N+1 query for `runner.builds.count`
|
2019-06-25 13:54:42 -04:00
|
|
|
# We also need to add 1 because it takes 2 queries to preload tags
|
|
|
|
expect { get :index }.not_to exceed_query_limit(control_count + 6)
|
2019-02-26 14:30:43 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-02-26 14:30:43 -05:00
|
|
|
expect(response.body).to have_content('tag1')
|
|
|
|
expect(response.body).to have_content('tag2')
|
|
|
|
end
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#show' do
|
2020-01-24 07:09:01 -05:00
|
|
|
render_views
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:project_two) { create(:project) }
|
|
|
|
|
|
|
|
before_all do
|
|
|
|
create(:ci_build, runner: runner, project: project)
|
|
|
|
create(:ci_build, runner: runner, project: project_two)
|
|
|
|
end
|
|
|
|
|
2017-02-15 06:16:12 -05:00
|
|
|
it 'shows a particular runner' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { id: runner.id }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows 404 for unknown runner' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { id: 0 }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
2020-01-24 07:09:01 -05:00
|
|
|
|
|
|
|
it 'avoids N+1 queries', :request_store do
|
|
|
|
get :show, params: { id: runner.id }
|
|
|
|
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new { get :show, params: { id: runner.id } }.count
|
|
|
|
|
|
|
|
new_project = create(:project)
|
|
|
|
create(:ci_build, runner: runner, project: new_project)
|
|
|
|
|
|
|
|
# There is one additional query looking up subject.group in ProjectPolicy for the
|
|
|
|
# needs_new_sso_session permission
|
|
|
|
expect { get :show, params: { id: runner.id } }.not_to exceed_query_limit(control_count + 1)
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-01-24 07:09:01 -05:00
|
|
|
end
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
|
|
|
it 'updates the runner and ticks the queue' do
|
|
|
|
new_desc = runner.description.swapcase
|
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :update, params: { id: runner.id, runner: { description: new_desc } }
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.description).to eq(new_desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
it 'destroys the runner' do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: { id: runner.id }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(Ci::Runner.find_by(id: runner.id)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resume' do
|
|
|
|
it 'marks the runner as active and ticks the queue' do
|
|
|
|
runner.update(active: false)
|
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resume, params: { id: runner.id }
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.active).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pause' do
|
|
|
|
it 'marks the runner as inactive and ticks the queue' do
|
|
|
|
runner.update(active: true)
|
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :pause, params: { id: runner.id }
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-02-06 13:08:54 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.active).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|