-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔊 Add better logging when loading the Shoryuken environment #691
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,36 @@ | |
RSpec.describe Shoryuken::EnvironmentLoader do | ||
subject { described_class.new({}) } | ||
|
||
describe '#load' do | ||
before do | ||
Shoryuken.groups.clear | ||
# See issue: https://stackoverflow.com/a/63699568 for stubbing AWS errors | ||
allow(Shoryuken::Client) | ||
.to receive(:queues) | ||
.with('stubbed_queue') | ||
.and_raise(Aws::SQS::Errors::NonExistentQueue.new(nil, nil)) | ||
allow(subject).to receive(:load_rails) | ||
allow(subject).to receive(:prefix_active_job_queue_names) | ||
allow(subject).to receive(:require_workers) | ||
allow(subject).to receive(:validate_workers) | ||
allow(subject).to receive(:patch_deprecated_workers) | ||
Shoryuken.options[:groups] = [['custom', { queues: ['stubbed_queue'] }]] | ||
end | ||
|
||
context "when given queues don't exist" do | ||
specify do | ||
expect { subject.load }.to raise_error( | ||
ArgumentError, | ||
<<-MSG.gsub(/^\s+/, '') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This solution looks good! Like you said, this isn't a hot path, so the performance won't matter much. |
||
The specified queue(s) stubbed_queue do not exist. | ||
Try 'shoryuken sqs create QUEUE-NAME' for creating a queue with default settings. | ||
It's also possible that you don't have permission to access the specified queues. | ||
MSG | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe '#parse_queues loads default queues' do | ||
before do | ||
allow(subject).to receive(:load_rails) | ||
|
@@ -34,7 +64,7 @@ | |
|
||
specify do | ||
Shoryuken.options[:queues] = ['queue1', 'queue2'] # default queues | ||
Shoryuken.options[:groups] = [[ 'custom', { queues: ['queue3'], delay: 25 }]] | ||
Shoryuken.options[:groups] = [['custom', { queues: ['queue3'], delay: 25 }]] | ||
subject.load | ||
|
||
expect(Shoryuken.groups['default'][:queues]).to eq(%w[queue1 queue2]) | ||
|
@@ -44,7 +74,6 @@ | |
end | ||
end | ||
|
||
|
||
describe '#prefix_active_job_queue_names' do | ||
before do | ||
allow(subject).to receive(:load_rails) | ||
|
@@ -76,7 +105,7 @@ | |
|
||
it 'does not prefix url-based queues' do | ||
Shoryuken.options[:queues] = ['https://example.com/test_queue1'] | ||
Shoryuken.options[:groups] = {'group1' => {queues: ['https://example.com/test_group1_queue1']}} | ||
Shoryuken.options[:groups] = { 'group1' => { queues: ['https://example.com/test_group1_queue1'] } } | ||
|
||
subject.load | ||
|
||
|
@@ -86,31 +115,35 @@ | |
|
||
it 'does not prefix arn-based queues' do | ||
Shoryuken.options[:queues] = ['arn:aws:sqs:fake-region-1:1234:test_queue1'] | ||
Shoryuken.options[:groups] = {'group1' => {queues: ['arn:aws:sqs:fake-region-1:1234:test_group1_queue1']}} | ||
Shoryuken.options[:groups] = { 'group1' => { queues: ['arn:aws:sqs:fake-region-1:1234:test_group1_queue1'] } } | ||
|
||
subject.load | ||
|
||
expect(Shoryuken.groups['default'][:queues]).to(eq(['arn:aws:sqs:fake-region-1:1234:test_queue1'])) | ||
expect(Shoryuken.groups['group1'][:queues]).to(eq(['arn:aws:sqs:fake-region-1:1234:test_group1_queue1'])) | ||
end | ||
end | ||
|
||
describe "#setup_options" do | ||
let (:cli_queues) { { "queue1"=> 10, "queue2" => 20 } } | ||
let (:config_queues) { [["queue1", 8], ["queue2", 4]] } | ||
let(:cli_queues) { { "queue1" => 10, "queue2" => 20 } } | ||
let(:config_queues) { [["queue1", 8], ["queue2", 4]] } | ||
|
||
context "when given queues through config and CLI" do | ||
specify do | ||
allow_any_instance_of(Shoryuken::EnvironmentLoader).to receive(:config_file_options).and_return({ queues: config_queues }) | ||
Shoryuken::EnvironmentLoader.setup_options(queues: cli_queues) | ||
expect(Shoryuken.options[:queues]).to eq(cli_queues) | ||
end | ||
end | ||
|
||
context "when given queues through config only" do | ||
specify do | ||
allow_any_instance_of(Shoryuken::EnvironmentLoader).to receive(:config_file_options).and_return({ queues: config_queues }) | ||
Shoryuken::EnvironmentLoader.setup_options({}) | ||
expect(Shoryuken.options[:queues]).to eq(config_queues) | ||
end | ||
end | ||
|
||
context "when given queues through CLI only" do | ||
specify do | ||
Shoryuken::EnvironmentLoader.setup_options(queues: cli_queues) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess looking at this, I can do something else similar to - https://stackoverflow.com/a/54314792. It could be better to not depend on an underlying API which is susceptible to change in the specs, otherwise if AWS SDK changes number of parameters, etc. to the
Aws::ServiceError
class, this test would break. WDYT? @cjlaroseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about
stub_const
but it looks like it might be worth trying here!