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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/concerns/worker_attributes_spec.rb')
-rw-r--r--spec/workers/concerns/worker_attributes_spec.rb106
1 files changed, 68 insertions, 38 deletions
diff --git a/spec/workers/concerns/worker_attributes_spec.rb b/spec/workers/concerns/worker_attributes_spec.rb
index ad9d5eeccbe..5e8f68923fd 100644
--- a/spec/workers/concerns/worker_attributes_spec.rb
+++ b/spec/workers/concerns/worker_attributes_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe WorkerAttributes do
+ using RSpec::Parameterized::TableSyntax
+
let(:worker) do
Class.new do
def self.name
@@ -13,21 +15,64 @@ RSpec.describe WorkerAttributes do
end
end
- describe '.data_consistency' do
- context 'with valid data_consistency' do
- it 'returns correct data_consistency' do
- worker.data_consistency(:sticky)
-
- expect(worker.get_data_consistency).to eq(:sticky)
+ let(:child_worker) do
+ Class.new(worker) do
+ def self.name
+ "TestChildworker"
end
end
+ end
+
+ describe 'class attributes' do
+ # rubocop: disable Layout/LineLength
+ where(:getter, :setter, :default, :values, :expected) do
+ :get_feature_category | :feature_category | nil | [:foo] | :foo
+ :get_urgency | :urgency | :low | [:high] | :high
+ :get_data_consistency | :data_consistency | :always | [:sticky] | :sticky
+ :get_worker_resource_boundary | :worker_resource_boundary | :unknown | [:cpu] | :cpu
+ :get_weight | :weight | 1 | [3] | 3
+ :get_tags | :tags | [] | [:foo, :bar] | [:foo, :bar]
+ :get_deduplicate_strategy | :deduplicate | :until_executing | [:none] | :none
+ :get_deduplication_options | :deduplicate | {} | [:none, including_scheduled: true] | { including_scheduled: true }
+ :worker_has_external_dependencies? | :worker_has_external_dependencies! | false | [] | true
+ :idempotent? | :idempotent! | false | [] | true
+ :big_payload? | :big_payload! | false | [] | true
+ end
+ # rubocop: enable Layout/LineLength
+
+ with_them do
+ context 'when the attribute is set' do
+ before do
+ worker.public_send(setter, *values)
+ end
+
+ it 'returns the expected value' do
+ expect(worker.public_send(getter)).to eq(expected)
+ expect(child_worker.public_send(getter)).to eq(expected)
+ end
+ end
+
+ context 'when the attribute is not set' do
+ it 'returns the default value' do
+ expect(worker.public_send(getter)).to eq(default)
+ expect(child_worker.public_send(getter)).to eq(default)
+ end
+ end
+
+ context 'when the attribute is set in the child worker' do
+ before do
+ child_worker.public_send(setter, *values)
+ end
- context 'when data_consistency is not provided' do
- it 'defaults to :always' do
- expect(worker.get_data_consistency).to eq(:always)
+ it 'returns the default value for the parent, and the expected value for the child' do
+ expect(worker.public_send(getter)).to eq(default)
+ expect(child_worker.public_send(getter)).to eq(expected)
+ end
end
end
+ end
+ describe '.data_consistency' do
context 'with invalid data_consistency' do
it 'raise exception' do
expect { worker.data_consistency(:invalid) }
@@ -45,36 +90,12 @@ RSpec.describe WorkerAttributes do
it 'returns correct feature flag value' do
worker.data_consistency(:sticky, feature_flag: :test_feature_flag)
- expect(worker.get_data_consistency_feature_flag_enabled?).not_to be_truthy
+ expect(worker.get_data_consistency_feature_flag_enabled?).not_to be(true)
+ expect(child_worker.get_data_consistency_feature_flag_enabled?).not_to be(true)
end
end
end
- describe '.idempotent?' do
- subject(:idempotent?) { worker.idempotent? }
-
- context 'when the worker is idempotent' do
- before do
- worker.idempotent!
- end
-
- it { is_expected.to be_truthy }
- end
-
- context 'when the worker is not idempotent' do
- it { is_expected.to be_falsey }
- end
- end
-
- describe '.deduplicate' do
- it 'sets deduplication_strategy and deduplication_options' do
- worker.deduplicate(:until_executing, including_scheduled: true)
-
- expect(worker.send(:class_attributes)[:deduplication_strategy]).to eq(:until_executing)
- expect(worker.send(:class_attributes)[:deduplication_options]).to eq(including_scheduled: true)
- end
- end
-
describe '#deduplication_enabled?' do
subject(:deduplication_enabled?) { worker.deduplication_enabled? }
@@ -83,7 +104,10 @@ RSpec.describe WorkerAttributes do
worker.deduplicate(:until_executing)
end
- it { is_expected.to eq(true) }
+ it 'returns true' do
+ expect(worker.deduplication_enabled?).to be(true)
+ expect(child_worker.deduplication_enabled?).to be(true)
+ end
end
context 'when feature flag is set' do
@@ -99,7 +123,10 @@ RSpec.describe WorkerAttributes do
stub_feature_flags(my_feature_flag: true)
end
- it { is_expected.to eq(true) }
+ it 'returns true' do
+ expect(worker.deduplication_enabled?).to be(true)
+ expect(child_worker.deduplication_enabled?).to be(true)
+ end
end
context 'when the FF is disabled' do
@@ -107,7 +134,10 @@ RSpec.describe WorkerAttributes do
stub_feature_flags(my_feature_flag: false)
end
- it { is_expected.to eq(false) }
+ it 'returns false' do
+ expect(worker.deduplication_enabled?).to be(false)
+ expect(child_worker.deduplication_enabled?).to be(false)
+ end
end
end
end