Skip to content

Commit

Permalink
Fix Events#fire_on_stopped! double call, add test (puma#2497)
Browse files Browse the repository at this point in the history
Launcher#graceful_stop calls Events#fire_on_stopped!, and graceful_stop is called in Launcher#run

Added TestLauncher#test_fire_on_stopped
  • Loading branch information
MSP-Greg authored and JuanitoFatas committed Sep 9, 2022
1 parent dd10138 commit 8356efe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/puma/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def halt

# Begin async shutdown of the server gracefully
def stop
@events.fire_on_stopped!
@status = :stop
@runner.stop
end
Expand Down
20 changes: 20 additions & 0 deletions test/test_launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ def test_log_config_disabled
refute_match(/Configuration:/, launcher.events.stdout.string)
end

def test_fire_on_stopped
conf = Puma::Configuration.new do |c|
c.app -> {[200, {}, ['']]}
c.port UniquePort.call
end

launcher = launcher(conf)
launcher.events.on_booted {
sleep 1.1 unless Puma.mri?
launcher.stop
}
launcher.events.on_stopped { puts 'on_stopped called' }

out, = capture_io do
launcher.run
end
sleep 0.2 unless Puma.mri?
assert_equal 'on_stopped called', out.strip
end

private

def events
Expand Down

0 comments on commit 8356efe

Please sign in to comment.