diff options
Diffstat (limited to 'spec/workers/concerns')
-rw-r--r-- | spec/workers/concerns/application_worker_spec.rb | 34 | ||||
-rw-r--r-- | spec/workers/concerns/worker_attributes_spec.rb | 68 |
2 files changed, 102 insertions, 0 deletions
diff --git a/spec/workers/concerns/application_worker_spec.rb b/spec/workers/concerns/application_worker_spec.rb index 5c1a1d3ae8f..29c69ff8b4b 100644 --- a/spec/workers/concerns/application_worker_spec.rb +++ b/spec/workers/concerns/application_worker_spec.rb @@ -176,6 +176,40 @@ RSpec.describe ApplicationWorker do end end + describe '.perform_async' do + shared_examples_for 'worker utilizes load balancing capabilities' do |data_consistency| + before do + worker.data_consistency(data_consistency) + end + + it 'call perform_in' do + expect(worker).to receive(:perform_in).with(described_class::DEFAULT_DELAY_INTERVAL.seconds, 123) + + worker.perform_async(123) + end + end + + context 'when workers data consistency is :sticky' do + it_behaves_like 'worker utilizes load balancing capabilities', :sticky + end + + context 'when workers data consistency is :delayed' do + it_behaves_like 'worker utilizes load balancing capabilities', :delayed + end + + context 'when workers data consistency is :always' do + before do + worker.data_consistency(:always) + end + + it 'does not call perform_in' do + expect(worker).not_to receive(:perform_in) + + worker.perform_async + end + end + end + describe '.bulk_perform_async' do it 'enqueues jobs in bulk' do Sidekiq::Testing.fake! do diff --git a/spec/workers/concerns/worker_attributes_spec.rb b/spec/workers/concerns/worker_attributes_spec.rb index a654ecbd3e2..d4b17c65f46 100644 --- a/spec/workers/concerns/worker_attributes_spec.rb +++ b/spec/workers/concerns/worker_attributes_spec.rb @@ -62,6 +62,12 @@ RSpec.describe WorkerAttributes do end describe '.idempotent!' do + it 'sets `idempotent` attribute of the worker class to true' do + worker.idempotent! + + expect(worker.send(:class_attributes)[:idempotent]).to eq(true) + end + context 'when data consistency is not :always' do it 'raise exception' do worker.data_consistency(:sticky) @@ -71,4 +77,66 @@ RSpec.describe WorkerAttributes do 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? } + + context 'when no feature flag is set' do + before do + worker.deduplicate(:until_executing) + end + + it { is_expected.to eq(true) } + end + + context 'when feature flag is set' do + before do + skip_feature_flags_yaml_validation + skip_default_enabled_yaml_check + + worker.deduplicate(:until_executing, feature_flag: :my_feature_flag) + end + + context 'when the FF is enabled' do + before do + stub_feature_flags(my_feature_flag: true) + end + + it { is_expected.to eq(true) } + end + + context 'when the FF is disabled' do + before do + stub_feature_flags(my_feature_flag: false) + end + + it { is_expected.to eq(false) } + end + end + end end |