Skip to content

Commit

Permalink
Issue sidekiq#1901: Don't crash if provided config file is empty.
Browse files Browse the repository at this point in the history
Don't return result of YAML.load if false

added tests around empty config file

update changelog
  • Loading branch information
Jordan Day committed Aug 18, 2014
1 parent 587520d commit 381e4ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-----------

- Add queues list for each process to the Busy page. [davetoxa, #1897]
- Fix for crash caused by empty config file. [jordan0day, #1901]

3.2.2
-----------
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def write_pid
def parse_config(cfile)
opts = {}
if File.exist?(cfile)
opts = YAML.load(ERB.new(IO.read(cfile)).result)
opts = YAML.load(ERB.new(IO.read(cfile)).result) || opts
opts = opts.merge(opts.delete(environment) || {})
parse_queues(opts, opts.delete(:queues) || [])
else
Expand Down
29 changes: 29 additions & 0 deletions test/test_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,35 @@ class TestCli < Sidekiq::Test
end
end

describe 'with an empty config file' do
before do
@tmp_file = Tempfile.new('sidekiq-test')
@tmp_path = @tmp_file.path
@tmp_file.close!
end

after do
File.unlink @tmp_path if File.exist? @tmp_path
end

it 'takes a path' do
@cli.parse(['sidekiq', '-C', @tmp_path])
assert_equal @tmp_path, Sidekiq.options[:config_file]
end

it 'should have an identical options hash, except for config_file' do
@cli.parse(['sidekiq'])
old_options = Sidekiq.options.clone

@cli.parse(['sidekiq', '-C', @tmp_path])
new_options = Sidekiq.options.clone
refute_equal old_options, new_options

new_options.delete(:config_file)
assert_equal old_options, new_options
end
end

describe 'with config file and flags' do
before do
# We need an actual file here.
Expand Down

0 comments on commit 381e4ea

Please sign in to comment.