Commit a0d950ad authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '324045-remove-feature-flag' into 'master'

Drop abort_user_pipelines_on_block feature flag [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!57801
parents 8919aeb5 f678ab55
......@@ -353,12 +353,7 @@ class User < ApplicationRecord
# this state transition object in order to do a rollback.
# For this reason the tradeoff is to disable this cop.
after_transition any => :blocked do |user|
if Feature.enabled?(:abort_user_pipelines_on_block, user)
Ci::AbortPipelinesService.new.execute(user.pipelines)
else
Ci::CancelUserPipelinesService.new.execute(user)
end
Ci::AbortPipelinesService.new.execute(user.pipelines)
Ci::DisableUserPipelineSchedulesService.new.execute(user)
end
# rubocop: enable CodeReuse/ServiceClass
......
# frozen_string_literal: true
module Ci
class CancelUserPipelinesService
# rubocop: disable CodeReuse/ActiveRecord
# This is a bug with CodeReuse/ActiveRecord cop
# https://gitlab.com/gitlab-org/gitlab/issues/32332
def execute(user)
# TODO: fix N+1 queries https://gitlab.com/gitlab-org/gitlab/-/issues/300685
user.pipelines.cancelable.find_each(&:cancel_running)
ServiceResponse.success(message: 'Pipeline canceled')
rescue ActiveRecord::StaleObjectError
ServiceResponse.error(message: 'Error canceling pipeline')
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
---
title: Bulk-abort user pipelines on block
merge_request: 57801
author:
type: performance
---
name: abort_user_pipelines_on_block
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56126
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/324045
milestone: '13.10'
type: development
group: group::memory
default_enabled: false
......@@ -1790,28 +1790,14 @@ RSpec.describe User do
context 'when user has running CI pipelines' do
let(:service) { double }
let(:pipelines) { build_list(:ci_pipeline, 3, :running) }
context 'with abort_user_pipelines_on_block feature enabled' do
let(:pipelines) { build_list(:ci_pipeline, 3, :running) }
it 'aborts all running pipelines and related jobs' do
expect(user).to receive(:pipelines).and_return(pipelines)
expect(Ci::AbortPipelinesService).to receive(:new).and_return(service)
expect(service).to receive(:execute).with(pipelines)
it 'aborts all running pipelines and related jobs' do
stub_feature_flags(abort_user_pipelines_on_block: true)
expect(user).to receive(:pipelines).and_return(pipelines)
expect(Ci::AbortPipelinesService).to receive(:new).and_return(service)
expect(service).to receive(:execute).with(pipelines)
user.block
end
end
context 'with abort_user_pipelines_on_block feature disabled' do
it 'cancels all running pipelines and related jobs' do
stub_feature_flags(abort_user_pipelines_on_block: false)
expect(Ci::CancelUserPipelinesService).to receive(:new).and_return(service)
expect(service).to receive(:execute).with(user)
user.block
end
user.block
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::CancelUserPipelinesService do
describe '#execute' do
let(:user) { create(:user) }
subject { described_class.new.execute(user) }
context 'when user has running CI pipelines' do
let(:pipeline) { create(:ci_pipeline, :running, user: user) }
let!(:build) { create(:ci_build, :running, pipeline: pipeline) }
it 'cancels all running pipelines and related jobs', :sidekiq_might_not_need_inline do
subject
expect(pipeline.reload).to be_canceled
expect(build.reload).to be_canceled
end
end
context 'when an error ocurrs' do
it 'raises a service level error' do
service = double(execute: ServiceResponse.error(message: 'Error canceling pipeline'))
allow(::Ci::CancelUserPipelinesService).to receive(:new).and_return(service)
result = subject
expect(result).to be_a(ServiceResponse)
expect(result).to be_error
end
end
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