From 8356efe49ce8cc453a3e9aa595e69721fdd2474b Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Thu, 3 Dec 2020 10:40:34 -0600 Subject: [PATCH] Fix Events#fire_on_stopped! double call, add test (#2497) Launcher#graceful_stop calls Events#fire_on_stopped!, and graceful_stop is called in Launcher#run Added TestLauncher#test_fire_on_stopped --- lib/puma/launcher.rb | 1 - test/test_launcher.rb | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/puma/launcher.rb b/lib/puma/launcher.rb index 89e63896bf..1683460764 100644 --- a/lib/puma/launcher.rb +++ b/lib/puma/launcher.rb @@ -139,7 +139,6 @@ def halt # Begin async shutdown of the server gracefully def stop - @events.fire_on_stopped! @status = :stop @runner.stop end diff --git a/test/test_launcher.rb b/test/test_launcher.rb index ac790dce6b..3c9a57e958 100644 --- a/test/test_launcher.rb +++ b/test/test_launcher.rb @@ -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