diff options
Diffstat (limited to 'spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb')
-rw-r--r-- | spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb | 123 |
1 files changed, 86 insertions, 37 deletions
diff --git a/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb b/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb index 7b6578a0744..f41a441d6a6 100644 --- a/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb +++ b/spec/rubocop/cop/sidekiq_load_balancing/worker_data_consistency_spec.rb @@ -3,46 +3,95 @@ require 'rubocop_spec_helper' require_relative '../../../../rubocop/cop/sidekiq_load_balancing/worker_data_consistency' -RSpec.describe RuboCop::Cop::SidekiqLoadBalancing::WorkerDataConsistency do - before do - allow(cop) - .to receive(:in_worker?) - .and_return(true) - end +RSpec.describe RuboCop::Cop::SidekiqLoadBalancing::WorkerDataConsistency, feature_category: :scalability do + context 'when data_consistency is not set' do + it 'adds an offense when not defining data_consistency' do + expect_offense(<<~CODE) + class SomeWorker + ^^^^^^^^^^^^^^^^ Should define data_consistency expectation.[...] + include ApplicationWorker - it 'adds an offense when not defining data_consistency' do - expect_offense(<<~CODE) - class SomeWorker - ^^^^^^^^^^^^^^^^ Should define data_consistency expectation.[...] - include ApplicationWorker - - queue_namespace :pipeline_hooks - feature_category :continuous_integration - urgency :high - end - CODE - end + queue_namespace :pipeline_hooks + feature_category :continuous_integration + urgency :high + end + CODE + end + + it 'adds no offense when defining data_consistency' do + expect_no_offenses(<<~CODE) + class SomeWorker + include ApplicationWorker - it 'adds no offense when defining data_consistency' do - expect_no_offenses(<<~CODE) - class SomeWorker - include ApplicationWorker - - queue_namespace :pipeline_hooks - feature_category :continuous_integration - data_consistency :delayed - urgency :high - end - CODE + queue_namespace :pipeline_hooks + feature_category :continuous_integration + data_consistency :delayed + urgency :high + end + CODE + end + + it 'adds no offense when worker is not an ApplicationWorker' do + expect_no_offenses(<<~CODE) + class SomeWorker + queue_namespace :pipeline_hooks + feature_category :continuous_integration + urgency :high + end + CODE + end end - it 'adds no offense when worker is not an ApplicationWorker' do - expect_no_offenses(<<~CODE) - class SomeWorker - queue_namespace :pipeline_hooks - feature_category :continuous_integration - urgency :high - end - CODE + context 'when data_consistency set to :always' do + it 'adds an offense when using `always` data_consistency' do + expect_offense(<<~CODE) + class SomeWorker + include ApplicationWorker + data_consistency :always + ^^^^^^^ Refrain from using `:always` if possible.[...] + + queue_namespace :pipeline_hooks + feature_category :continuous_integration + urgency :high + end + CODE + end + + it 'adds no offense when using `sticky` data_consistency' do + expect_no_offenses(<<~CODE) + class SomeWorker + include ApplicationWorker + + data_consistency :sticky + queue_namespace :pipeline_hooks + feature_category :continuous_integration + urgency :high + end + CODE + end + + it 'adds no offense when using `delayed` data_consistency' do + expect_no_offenses(<<~CODE) + class SomeWorker + include ApplicationWorker + + data_consistency :delayed + queue_namespace :pipeline_hooks + feature_category :continuous_integration + urgency :high + end + CODE + end + + it 'adds no offense when worker is not an ApplicationWorker' do + expect_no_offenses(<<~CODE) + class SomeWorker + data_consistency :always + queue_namespace :pipeline_hooks + feature_category :continuous_integration + urgency :high + end + CODE + end end end |