Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-26 09:08:37 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-26 09:08:37 +0300
commit864dae0d98424b463501c21eda1b633c14956fa9 (patch)
tree9340f7dad0a32f7e8c8a3b5ad723fbf0de26c3ba /spec
parent47ef8c6c530ee1cac0e1046b098755ec949da894 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/ci/builds.rb6
-rw-r--r--spec/factories/clusters/applications/helm.rb13
-rw-r--r--spec/factories/commits.rb9
-rw-r--r--spec/factories/container_repositories.rb9
-rw-r--r--spec/factories/deployments.rb2
-rw-r--r--spec/factories/merge_requests.rb2
-rw-r--r--spec/factories/projects.rb4
-rw-r--r--spec/helpers/routing/pseudonymization_helper_spec.rb3
-rw-r--r--spec/lib/gitlab/ci/status/build/play_spec.rb7
-rw-r--r--spec/lib/gitlab/ci/status/build/scheduled_spec.rb5
-rw-r--r--spec/models/ci/bridge_spec.rb33
-rw-r--r--spec/support/factory_bot.rb1
-rw-r--r--spec/support/helpers/stub_method_calls.rb66
-rw-r--r--spec/support_specs/helpers/stub_method_calls_spec.rb107
-rw-r--r--spec/workers/every_sidekiq_worker_spec.rb2
-rw-r--r--spec/workers/issue_placement_worker_spec.rb151
-rw-r--r--spec/workers/issue_rebalancing_worker_spec.rb104
17 files changed, 215 insertions, 309 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index 56c12d73a3b..645c519aca2 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -494,13 +494,15 @@ FactoryBot.define do
trait :with_commit do
after(:build) do |build|
- allow(build).to receive(:commit).and_return build(:commit, :without_author)
+ commit = build(:commit, :without_author)
+ stub_method(build, :commit) { commit }
end
end
trait :with_commit_and_author do
after(:build) do |build|
- allow(build).to receive(:commit).and_return build(:commit)
+ commit = build(:commit)
+ stub_method(build, :commit) { commit }
end
end
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb
index 10fa739acc1..919b45e57e2 100644
--- a/spec/factories/clusters/applications/helm.rb
+++ b/spec/factories/clusters/applications/helm.rb
@@ -10,19 +10,18 @@ FactoryBot.define do
before(:create) do |_record, evaluator|
if evaluator.helm_installed
- allow(Gitlab::Kubernetes::Helm::V2::Certificate).to receive(:generate_root)
- .and_return(
- double(
- key_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_key.key')),
- cert_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem'))
- )
+ stub_method(Gitlab::Kubernetes::Helm::V2::Certificate, :generate_root) do
+ OpenStruct.new( # rubocop: disable Style/OpenStructUse
+ key_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_key.key')),
+ cert_string: File.read(Rails.root.join('spec/fixtures/clusters/sample_cert.pem'))
)
+ end
end
end
after(:create) do |_record, evaluator|
if evaluator.helm_installed
- allow(Gitlab::Kubernetes::Helm::V2::Certificate).to receive(:generate_root).and_call_original
+ restore_original_methods(Gitlab::Kubernetes::Helm::V2::Certificate)
end
end
diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb
index d006f9baf1f..4b1c74110ef 100644
--- a/spec/factories/commits.rb
+++ b/spec/factories/commits.rb
@@ -28,19 +28,20 @@ FactoryBot.define do
end
after(:build) do |commit, evaluator|
- allow(commit).to receive(:author).and_return(evaluator.author || build_stubbed(:author))
- allow(commit).to receive(:parent_ids).and_return([])
+ author = evaluator.author || build_stubbed(:author)
+ stub_method(commit, :author) { author }
+ stub_method(commit, :parent_ids) { [] }
end
trait :merge_commit do
after(:build) do |commit|
- allow(commit).to receive(:parent_ids).and_return(Array.new(2) { SecureRandom.hex(20) })
+ stub_method(commit, :parent_ids) { Array.new(2) { SecureRandom.hex(20) } }
end
end
trait :without_author do
after(:build) do |commit|
- allow(commit).to receive(:author).and_return nil
+ stub_method(commit, :author) { nil }
end
end
end
diff --git a/spec/factories/container_repositories.rb b/spec/factories/container_repositories.rb
index ce83e9e8006..210441430b0 100644
--- a/spec/factories/container_repositories.rb
+++ b/spec/factories/container_repositories.rb
@@ -85,13 +85,12 @@ FactoryBot.define do
tags = evaluator.tags
# convert Array into Hash
tags = tags.product(['sha256:4c8e63ca4cb663ce6c688cb06f1c372b088dac5b6d7ad7d49cd620d85cf72a15']).to_h unless tags.is_a?(Hash)
-
- allow(repository.client)
- .to receive(:repository_tags)
- .and_return({
+ stub_method(repository.client, :repository_tags) do |*args|
+ {
'name' => repository.path,
'tags' => tags.keys
- })
+ }
+ end
tags.each_pair do |tag, digest|
allow(repository.client)
diff --git a/spec/factories/deployments.rb b/spec/factories/deployments.rb
index ab1b794632a..204b917fa4a 100644
--- a/spec/factories/deployments.rb
+++ b/spec/factories/deployments.rb
@@ -15,7 +15,7 @@ FactoryBot.define do
deployment.user ||= deployment.project.creator
unless deployment.project.repository_exists?
- allow(deployment.project.repository).to receive(:create_ref)
+ stub_method(deployment.project.repository, :create_ref) { nil }
end
if deployment.cluster && deployment.cluster.project_type? && deployment.cluster.project.nil?
diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb
index cba66b5d414..4941a31982f 100644
--- a/spec/factories/merge_requests.rb
+++ b/spec/factories/merge_requests.rb
@@ -320,7 +320,7 @@ FactoryBot.define do
# Fake `fetch_ref!` if we don't have repository
# We have too many existing tests relying on this behaviour
unless [target_project, source_project].all?(&:repository_exists?)
- allow(merge_request).to receive(:fetch_ref!)
+ stub_method(merge_request, :fetch_ref!) { nil }
end
end
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb
index c3c02782578..a5efadefc76 100644
--- a/spec/factories/projects.rb
+++ b/spec/factories/projects.rb
@@ -301,8 +301,8 @@ FactoryBot.define do
trait :stubbed_repository do
after(:build) do |project|
- allow(project).to receive(:empty_repo?).and_return(false)
- allow(project.repository).to receive(:empty?).and_return(false)
+ stub_method(project, :empty_repo?) { false }
+ stub_method(project.repository, :empty?) { false }
end
end
diff --git a/spec/helpers/routing/pseudonymization_helper_spec.rb b/spec/helpers/routing/pseudonymization_helper_spec.rb
index cf716931fe2..dd4cc55ed2b 100644
--- a/spec/helpers/routing/pseudonymization_helper_spec.rb
+++ b/spec/helpers/routing/pseudonymization_helper_spec.rb
@@ -8,8 +8,7 @@ RSpec.describe ::Routing::PseudonymizationHelper do
let_it_be(:project) { create(:project, group: group) }
let_it_be(:subproject) { create(:project, group: subgroup) }
let_it_be(:issue) { create(:issue, project: project) }
-
- let(:merge_request) { create(:merge_request, source_project: project) }
+ let_it_be(:merge_request) { create(:merge_request, source_project: project) }
let(:subject) { helper.masked_page_url(group: group, project: project) }
diff --git a/spec/lib/gitlab/ci/status/build/play_spec.rb b/spec/lib/gitlab/ci/status/build/play_spec.rb
index bb406623d2f..ade07a54877 100644
--- a/spec/lib/gitlab/ci/status/build/play_spec.rb
+++ b/spec/lib/gitlab/ci/status/build/play_spec.rb
@@ -3,9 +3,10 @@
require 'spec_helper'
RSpec.describe Gitlab::Ci::Status::Build::Play do
- let(:user) { create(:user) }
- let(:project) { create(:project, :stubbed_repository) }
- let(:build) { create(:ci_build, :manual, project: project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :stubbed_repository) }
+ let_it_be_with_refind(:build) { create(:ci_build, :manual, project: project) }
+
let(:status) { Gitlab::Ci::Status::Core.new(build, user) }
subject { described_class.new(status) }
diff --git a/spec/lib/gitlab/ci/status/build/scheduled_spec.rb b/spec/lib/gitlab/ci/status/build/scheduled_spec.rb
index b0cd1ac4dc5..a9f9b82767e 100644
--- a/spec/lib/gitlab/ci/status/build/scheduled_spec.rb
+++ b/spec/lib/gitlab/ci/status/build/scheduled_spec.rb
@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe Gitlab::Ci::Status::Build::Scheduled do
- let(:user) { create(:user) }
- let(:project) { create(:project, :stubbed_repository) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project, :stubbed_repository) }
+
let(:build) { create(:ci_build, :scheduled, project: project) }
let(:status) { Gitlab::Ci::Status::Core.new(build, user) }
diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb
index 6409ea9fc3d..cb29cce554f 100644
--- a/spec/models/ci/bridge_spec.rb
+++ b/spec/models/ci/bridge_spec.rb
@@ -259,25 +259,16 @@ RSpec.describe Ci::Bridge do
context 'forward variables' do
using RSpec::Parameterized::TableSyntax
- where(:yaml_variables, :pipeline_variables, :ff, :variables) do
- nil | nil | true | %w[BRIDGE]
- nil | false | true | %w[BRIDGE]
- nil | true | true | %w[BRIDGE PVAR1]
- false | nil | true | %w[]
- false | false | true | %w[]
- false | true | true | %w[PVAR1]
- true | nil | true | %w[BRIDGE]
- true | false | true | %w[BRIDGE]
- true | true | true | %w[BRIDGE PVAR1]
- nil | nil | false | %w[BRIDGE]
- nil | false | false | %w[BRIDGE]
- nil | true | false | %w[BRIDGE]
- false | nil | false | %w[BRIDGE]
- false | false | false | %w[BRIDGE]
- false | true | false | %w[BRIDGE]
- true | nil | false | %w[BRIDGE]
- true | false | false | %w[BRIDGE]
- true | true | false | %w[BRIDGE]
+ where(:yaml_variables, :pipeline_variables, :variables) do
+ nil | nil | %w[BRIDGE]
+ nil | false | %w[BRIDGE]
+ nil | true | %w[BRIDGE PVAR1]
+ false | nil | %w[]
+ false | false | %w[]
+ false | true | %w[PVAR1]
+ true | nil | %w[BRIDGE]
+ true | false | %w[BRIDGE]
+ true | true | %w[BRIDGE PVAR1]
end
with_them do
@@ -292,10 +283,6 @@ RSpec.describe Ci::Bridge do
}
end
- before do
- stub_feature_flags(ci_trigger_forward_variables: ff)
- end
-
it 'returns variables according to the forward value' do
expect(bridge.downstream_variables.map { |v| v[:key] }).to contain_exactly(*variables)
end
diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb
index 5f22fa11e9e..6faa2db3330 100644
--- a/spec/support/factory_bot.rb
+++ b/spec/support/factory_bot.rb
@@ -2,6 +2,7 @@
FactoryBot::SyntaxRunner.class_eval do
include RSpec::Mocks::ExampleMethods
+ include StubMethodCalls
# FactoryBot doesn't allow yet to add a helper that can be used in factories
# While the fixture_file_upload helper is reasonable to be used there:
diff --git a/spec/support/helpers/stub_method_calls.rb b/spec/support/helpers/stub_method_calls.rb
new file mode 100644
index 00000000000..45d704958ca
--- /dev/null
+++ b/spec/support/helpers/stub_method_calls.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+# Used to stud methods for factories where we can't
+# use rspec-mocks.
+#
+# Examples:
+# stub_method(user, :some_method) { |var1, var2| var1 + var2 }
+# stub_method(user, :some_method) { true }
+# stub_method(user, :some_method) => nil
+# stub_method(user, :some_method) do |*args|
+# true
+# end
+#
+# restore_original_method(user, :some_method)
+# restore_original_methods(user)
+#
+module StubMethodCalls
+ AlreadyImplementedError = Class.new(StandardError)
+
+ def stub_method(object, method, &block)
+ Backup.stub_method(object, method, &block)
+ end
+
+ def restore_original_method(object, method)
+ Backup.restore_method(object, method)
+ end
+
+ def restore_original_methods(object)
+ Backup.stubbed_methods(object).each_key { |method, backed_up_method| restore_original_method(object, method) }
+ end
+
+ module Backup
+ def self.stubbed_methods(object)
+ return {} unless object.respond_to?(:_stubbed_methods)
+
+ object._stubbed_methods
+ end
+
+ def self.backup_method(object, method)
+ backed_up_methods = stubbed_methods(object)
+ backed_up_methods[method] = object.respond_to?(method) ? object.method(method) : nil
+
+ object.define_singleton_method(:_stubbed_methods) { backed_up_methods }
+ end
+
+ def self.stub_method(object, method, &block)
+ raise ArgumentError, "Block is required" unless block_given?
+
+ backup_method(object, method) unless backed_up_method?(object, method)
+ object.define_singleton_method(method, &block)
+ end
+
+ def self.restore_method(object, method)
+ raise NotImplementedError, "#{method} has not been stubbed on #{object}" unless backed_up_method?(object, method)
+
+ object.singleton_class.remove_method(method)
+ backed_up_method = stubbed_methods(object)[method]
+
+ object.define_singleton_method(method, backed_up_method) if backed_up_method
+ end
+
+ def self.backed_up_method?(object, method)
+ stubbed_methods(object).key?(method)
+ end
+ end
+end
diff --git a/spec/support_specs/helpers/stub_method_calls_spec.rb b/spec/support_specs/helpers/stub_method_calls_spec.rb
new file mode 100644
index 00000000000..837a2162bcd
--- /dev/null
+++ b/spec/support_specs/helpers/stub_method_calls_spec.rb
@@ -0,0 +1,107 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe StubMethodCalls do
+ include described_class
+
+ let(:object) do
+ Class.new do
+ def self.test_method
+ 'test'
+ end
+
+ def self.test_method_two(response: nil)
+ response || 'test_two'
+ end
+ end
+ end
+
+ describe '#stub_method' do
+ let(:method_to_stub) { :test_method }
+
+ it 'stubs the method response' do
+ stub_method(object, method_to_stub) { true }
+
+ expect(object.send(method_to_stub)).to eq(true)
+ end
+
+ context 'when calling it on an already stubbed method' do
+ before do
+ stub_method(object, method_to_stub) { false }
+ end
+
+ it 'stubs correctly' do
+ stub_method(object, method_to_stub) { true }
+
+ expect(object.send(method_to_stub)).to eq(true)
+ end
+ end
+
+ context 'methods that accept arguments' do
+ it 'stubs correctly' do
+ stub_method(object, method_to_stub) { |a, b| a + b }
+
+ expect(object.send(method_to_stub, 1, 2)).to eq(3)
+ end
+
+ context 'methods that use named arguments' do
+ let(:method_to_stub) { :test_method_two }
+
+ it 'stubs correctly' do
+ stub_method(object, method_to_stub) { |a: 'test'| a }
+
+ expect(object.send(method_to_stub, a: 'testing')).to eq('testing')
+ expect(object.send(method_to_stub)).to eq('test')
+ end
+
+ context 'stubbing non-existent method' do
+ let(:method_to_stub) { :another_method }
+
+ it 'stubs correctly' do
+ stub_method(object, method_to_stub) { |a: 'test'| a }
+
+ expect(object.send(method_to_stub, a: 'testing')).to eq('testing')
+ expect(object.send(method_to_stub)).to eq('test')
+ end
+ end
+ end
+ end
+ end
+
+ describe '#restore_original_method' do
+ before do
+ stub_method(object, :test_method) { true }
+ end
+
+ it 'restores original behaviour' do
+ expect(object.test_method).to eq(true)
+
+ restore_original_method(object, :test_method)
+
+ expect(object.test_method).to eq('test')
+ end
+
+ context 'method is not stubbed' do
+ specify do
+ expect do
+ restore_original_method(object, 'some_other_method')
+ end.to raise_error(NotImplementedError, "some_other_method has not been stubbed on #{object}")
+ end
+ end
+ end
+
+ describe '#restore_original_methods' do
+ before do
+ stub_method(object, :test_method) { true }
+ stub_method(object, :test_method_two) { true }
+ end
+
+ it 'restores original behaviour' do
+ restore_original_methods(object)
+
+ expect(object.test_method).to eq('test')
+ expect(object.test_method_two).to eq('test_two')
+ end
+ end
+end
diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb
index c15d1198ded..b1532b01d3f 100644
--- a/spec/workers/every_sidekiq_worker_spec.rb
+++ b/spec/workers/every_sidekiq_worker_spec.rb
@@ -308,8 +308,6 @@ RSpec.describe 'Every Sidekiq worker' do
'InvalidGpgSignatureUpdateWorker' => 3,
'IrkerWorker' => 3,
'IssuableExportCsvWorker' => 3,
- 'IssuePlacementWorker' => 3,
- 'IssueRebalancingWorker' => 3,
'Issues::PlacementWorker' => 3,
'Issues::RebalancingWorker' => 3,
'IterationsUpdateStatusWorker' => 3,
diff --git a/spec/workers/issue_placement_worker_spec.rb b/spec/workers/issue_placement_worker_spec.rb
deleted file mode 100644
index 9b5121d98e8..00000000000
--- a/spec/workers/issue_placement_worker_spec.rb
+++ /dev/null
@@ -1,151 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe IssuePlacementWorker do
- describe '#perform' do
- let_it_be(:time) { Time.now.utc }
- let_it_be(:group) { create(:group) }
- let_it_be(:project) { create(:project, group: group) }
- let_it_be(:author) { create(:user) }
- let_it_be(:common_attrs) { { author: author, project: project } }
- let_it_be(:unplaced) { common_attrs.merge(relative_position: nil) }
- let_it_be_with_reload(:issue) { create(:issue, **unplaced, created_at: time) }
- let_it_be_with_reload(:issue_a) { create(:issue, **unplaced, created_at: time - 1.minute) }
- let_it_be_with_reload(:issue_b) { create(:issue, **unplaced, created_at: time - 2.minutes) }
- let_it_be_with_reload(:issue_c) { create(:issue, **unplaced, created_at: time + 1.minute) }
- let_it_be_with_reload(:issue_d) { create(:issue, **unplaced, created_at: time + 2.minutes) }
- let_it_be_with_reload(:issue_e) { create(:issue, **common_attrs, relative_position: 10, created_at: time + 1.minute) }
- let_it_be_with_reload(:issue_f) { create(:issue, **unplaced, created_at: time + 1.minute) }
-
- let_it_be(:irrelevant) { create(:issue, relative_position: nil, created_at: time) }
-
- shared_examples 'running the issue placement worker' do
- let(:issue_id) { issue.id }
- let(:project_id) { project.id }
-
- it 'places all issues created at most 5 minutes before this one at the end, most recent last' do
- expect { run_worker }.not_to change { irrelevant.reset.relative_position }
-
- expect(project.issues.order_by_relative_position)
- .to eq([issue_e, issue_b, issue_a, issue, issue_c, issue_f, issue_d])
- expect(project.issues.where(relative_position: nil)).not_to exist
- end
-
- it 'schedules rebalancing if needed' do
- issue_a.update!(relative_position: RelativePositioning::MAX_POSITION)
-
- expect(Issues::RebalancingWorker).to receive(:perform_async).with(nil, nil, project.group.id)
-
- run_worker
- end
-
- context 'there are more than QUERY_LIMIT unplaced issues' do
- before_all do
- # Ensure there are more than N issues in this set
- n = described_class::QUERY_LIMIT
- create_list(:issue, n - 5, **unplaced)
- end
-
- it 'limits the sweep to QUERY_LIMIT records, and reschedules placement' do
- expect(Issue).to receive(:move_nulls_to_end)
- .with(have_attributes(count: described_class::QUERY_LIMIT))
- .and_call_original
-
- expect(Issues::PlacementWorker).to receive(:perform_async).with(nil, project.id)
-
- run_worker
-
- expect(project.issues.where(relative_position: nil)).to exist
- end
-
- it 'is eventually correct' do
- prefix = project.issues.where.not(relative_position: nil).order(:relative_position).to_a
- moved = project.issues.where.not(id: prefix.map(&:id))
-
- run_worker
-
- expect(project.issues.where(relative_position: nil)).to exist
-
- run_worker
-
- expect(project.issues.where(relative_position: nil)).not_to exist
- expect(project.issues.order(:relative_position)).to eq(prefix + moved.order(:created_at, :id))
- end
- end
-
- context 'we are passed bad IDs' do
- let(:issue_id) { non_existing_record_id }
- let(:project_id) { non_existing_record_id }
-
- def max_positions_by_project
- Issue
- .group(:project_id)
- .pluck(:project_id, Issue.arel_table[:relative_position].maximum.as('max_relative_position'))
- .to_h
- end
-
- it 'does move any issues to the end' do
- expect { run_worker }.not_to change { max_positions_by_project }
- end
-
- context 'the project_id refers to an empty project' do
- let!(:project_id) { create(:project).id }
-
- it 'does move any issues to the end' do
- expect { run_worker }.not_to change { max_positions_by_project }
- end
- end
- end
-
- it 'anticipates the failure to place the issues, and schedules rebalancing' do
- allow(Issue).to receive(:move_nulls_to_end) { raise RelativePositioning::NoSpaceLeft }
-
- expect(Issues::RebalancingWorker).to receive(:perform_async).with(nil, nil, project.group.id)
- expect(Gitlab::ErrorTracking)
- .to receive(:log_exception)
- .with(RelativePositioning::NoSpaceLeft, worker_arguments)
-
- run_worker
- end
- end
-
- context 'passing an issue ID' do
- def run_worker
- described_class.new.perform(issue_id)
- end
-
- let(:worker_arguments) { { issue_id: issue_id, project_id: nil } }
-
- it_behaves_like 'running the issue placement worker'
-
- context 'when block_issue_repositioning is enabled' do
- let(:issue_id) { issue.id }
- let(:project_id) { project.id }
-
- before do
- stub_feature_flags(block_issue_repositioning: group)
- end
-
- it 'does not run repositioning tasks' do
- expect { run_worker }.not_to change { issue.reset.relative_position }
- end
- end
- end
-
- context 'passing a project ID' do
- def run_worker
- described_class.new.perform(nil, project_id)
- end
-
- let(:worker_arguments) { { issue_id: nil, project_id: project_id } }
-
- it_behaves_like 'running the issue placement worker'
- end
- end
-
- it 'has the `until_executed` deduplicate strategy' do
- expect(described_class.get_deduplicate_strategy).to eq(:until_executed)
- expect(described_class.get_deduplication_options).to include({ including_scheduled: true })
- end
-end
diff --git a/spec/workers/issue_rebalancing_worker_spec.rb b/spec/workers/issue_rebalancing_worker_spec.rb
deleted file mode 100644
index cfb19af05b3..00000000000
--- a/spec/workers/issue_rebalancing_worker_spec.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe IssueRebalancingWorker, :clean_gitlab_redis_shared_state do
- describe '#perform' do
- let_it_be(:group) { create(:group) }
- let_it_be(:project) { create(:project, group: group) }
- let_it_be(:issue) { create(:issue, project: project) }
-
- shared_examples 'running the worker' do
- it 'runs an instance of Issues::RelativePositionRebalancingService' do
- service = double(execute: nil)
- service_param = arguments.second.present? ? kind_of(Project.id_in([project]).class) : kind_of(group&.all_projects.class)
-
- expect(Issues::RelativePositionRebalancingService).to receive(:new).with(service_param).and_return(service)
-
- described_class.new.perform(*arguments)
- end
-
- it 'anticipates there being too many concurent rebalances' do
- service = double
- service_param = arguments.second.present? ? kind_of(Project.id_in([project]).class) : kind_of(group&.all_projects.class)
-
- allow(service).to receive(:execute).and_raise(Issues::RelativePositionRebalancingService::TooManyConcurrentRebalances)
- expect(Issues::RelativePositionRebalancingService).to receive(:new).with(service_param).and_return(service)
- expect(Gitlab::ErrorTracking).to receive(:log_exception).with(Issues::RelativePositionRebalancingService::TooManyConcurrentRebalances, include(project_id: arguments.second, root_namespace_id: arguments.third))
-
- described_class.new.perform(*arguments)
- end
-
- it 'takes no action if the value is nil' do
- expect(Issues::RelativePositionRebalancingService).not_to receive(:new)
- expect(Gitlab::ErrorTracking).not_to receive(:log_exception)
-
- described_class.new.perform # all arguments are nil
- end
-
- it 'does not schedule a new rebalance if it finished under 1h ago' do
- container_type = arguments.second.present? ? ::Gitlab::Issues::Rebalancing::State::PROJECT : ::Gitlab::Issues::Rebalancing::State::NAMESPACE
- container_id = arguments.second || arguments.third
-
- Gitlab::Redis::SharedState.with do |redis|
- redis.set(::Gitlab::Issues::Rebalancing::State.send(:recently_finished_key, container_type, container_id), true)
- end
-
- expect(Issues::RelativePositionRebalancingService).not_to receive(:new)
- expect(Gitlab::ErrorTracking).not_to receive(:log_exception)
-
- described_class.new.perform(*arguments)
- end
- end
-
- shared_examples 'safely handles non-existent ids' do
- it 'anticipates the inability to find the issue' do
- expect(Gitlab::ErrorTracking).to receive(:log_exception).with(ArgumentError, include(project_id: arguments.second, root_namespace_id: arguments.third))
- expect(Issues::RelativePositionRebalancingService).not_to receive(:new)
-
- described_class.new.perform(*arguments)
- end
- end
-
- context 'without root_namespace param' do
- it_behaves_like 'running the worker' do
- let(:arguments) { [-1, project.id] }
- end
-
- it_behaves_like 'safely handles non-existent ids' do
- let(:arguments) { [nil, -1] }
- end
-
- include_examples 'an idempotent worker' do
- let(:job_args) { [-1, project.id] }
- end
-
- include_examples 'an idempotent worker' do
- let(:job_args) { [nil, -1] }
- end
- end
-
- context 'with root_namespace param' do
- it_behaves_like 'running the worker' do
- let(:arguments) { [nil, nil, group.id] }
- end
-
- it_behaves_like 'safely handles non-existent ids' do
- let(:arguments) { [nil, nil, -1] }
- end
-
- include_examples 'an idempotent worker' do
- let(:job_args) { [nil, nil, group.id] }
- end
-
- include_examples 'an idempotent worker' do
- let(:job_args) { [nil, nil, -1] }
- end
- end
- end
-
- it 'has the `until_executed` deduplicate strategy' do
- expect(described_class.get_deduplicate_strategy).to eq(:until_executed)
- expect(described_class.get_deduplication_options).to include({ including_scheduled: true })
- end
-end