Skip to content

Commit

Permalink
Raise an error when no available Rack server was found
Browse files Browse the repository at this point in the history
  • Loading branch information
mishina2228 committed Sep 21, 2022
1 parent daf45bb commit b9254a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/resque/web_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def setup_rack_handler
next
end
end
raise 'No available Rack handler (e.g. WEBrick, Thin, Puma, etc.) was found.' if handler.nil?

handler

# :server might be set explicitly to a single option like "mongrel"
Expand Down
41 changes: 40 additions & 1 deletion test/resque-web_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,50 @@ def web_runner(*args)
Resque::Server.set :server, false
end

it 'sets the rack handler automaticaly' do
it 'sets the rack handler automatically' do
assert_equal @runner.rack_handler, Rack::Handler::WEBrick
end
end

describe 'with a sinatra app without an explicit server setting' do
def web_runner(*args)
Resque::WebRunner.any_instance.stubs(:daemonize!).once
Rack::Handler::WEBrick.stubs(:run).once
@runner = Resque::WebRunner.new(*args)
end

before do
Resque::Server.set :server, ["invalid", "webrick", "thin"]
Rack::Handler::WEBrick.stubs(:run)
web_runner("route", "--debug", skip_launch: true, sessions: true)
end

after do
Resque::Server.set :server, false
end

it 'sets the first valid rack handler' do
assert_equal @runner.rack_handler, Rack::Handler::WEBrick
end
end

describe 'with a sinatra app without available server settings' do
before do
Resque::Server.set :server, ["invalid"]
end

after do
Resque::Server.set :server, false
end

it 'raises an error indicating that no available Rack handler was found' do
err = assert_raises StandardError do
Resque::WebRunner.new(skip_launch: true, sessions: true)
end
assert_match('No available Rack handler (e.g. WEBrick, Thin, Puma, etc.) was found.', err.message)
end
end

describe 'with a simple rack app' do
before do
web_runner(skip_launch: true, sessions: true)
Expand Down

0 comments on commit b9254a5

Please sign in to comment.