-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write basic specs ; clean up setup and file structure
- Loading branch information
Showing
7 changed files
with
63 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,4 +111,5 @@ Style/StringLiterals: | |
Style/Documentation: | ||
Enabled: false | ||
|
||
|
||
RSpec/AnyInstance: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require "sidekiq_poison_pill_remedy" | ||
require "active_support" | ||
require "active_support/inflector" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require "sidekiq" | ||
require "sidekiq/api" | ||
require "sidekiq/testing" | ||
require "rspec-sidekiq" | ||
require "sidekiq-poison-pill-remedy" | ||
require "support/my_job" | ||
require "spec_helper" | ||
|
||
RSpec.describe SidekiqPoisonPillRemedy do | ||
before do | ||
Sidekiq::Testing.fake! | ||
end | ||
|
||
it "moves job to poison_pill queue and logs message" do | ||
puts "Starting test..." | ||
|
||
job_id = MyJob.perform_async(nil) | ||
|
||
|
||
expect(Sidekiq::Queue.new.size).to eq(1) | ||
expect(Sidekiq::Queue.new("poison_pill").size).to eq(0) | ||
puts "2" | ||
|
||
job = Sidekiq::Queue.new.find_job(job_id) | ||
|
||
SidekiqPoisonPillRemedy.remedy.call(nil, job) | ||
|
||
puts "Jobs in Queue: #{Sidekiq::Queue.new.size}" | ||
puts "3" | ||
|
||
expect(Sidekiq::Queue.new.size).to eq(0) | ||
expect(Sidekiq::Queue.new("poison_pill").size).to eq(1) | ||
describe ".remedy" do | ||
subject(:call) { described_class.remedy.call(nil, job) } | ||
|
||
let(:default_queue) { "default" } | ||
let(:poison_pill_queue) { "poison_pill" } | ||
let(:enqueue_job) { MyJob.set(queue: job_queue).perform_async("fail") } | ||
let(:job) { Sidekiq::Queue.new(default_queue).find_job(enqueue_job) } | ||
|
||
before do | ||
Sidekiq::Testing.disable! | ||
Sidekiq::Queue.new(poison_pill_queue).clear | ||
Sidekiq::Queue.new(default_queue).clear | ||
|
||
enqueue_job | ||
|
||
# there is no easy way to move the job to DeadSet, the process is rather complex | ||
# we would ideally execute a single method call have a proper setup but in that case | ||
# we need to use stub | ||
allow_any_instance_of(Sidekiq::DeadSet).to receive(:find_job).with(enqueue_job).and_return(job) | ||
end | ||
|
||
context "when the job is a poison pill in non-poison pill queue" do | ||
let(:job_queue) { default_queue } | ||
|
||
it "moves job to poison_pill queue and sends error notification" do | ||
expect do | ||
call | ||
end.to change { Sidekiq::Queue.new(default_queue).count }.from(1).to(0) | ||
.and change { Sidekiq::Queue.new(poison_pill_queue).count }.from(0).to(1) | ||
end | ||
end | ||
|
||
context "when the job is a poison pill in poison pill queue" do | ||
let(:job_queue) { poison_pill_queue } | ||
|
||
it "keep the jobs in posion pill queue and sends error notification" do | ||
expect do | ||
call | ||
end.to avoid_changing { Sidekiq::Queue.new(default_queue).count }.from(0) | ||
.and avoid_changing { Sidekiq::Queue.new(poison_pill_queue).count }.from(1) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters