diff --git a/lib/puma/dsl.rb b/lib/puma/dsl.rb index 36f0441056..3c38cd782c 100644 --- a/lib/puma/dsl.rb +++ b/lib/puma/dsl.rb @@ -585,7 +585,7 @@ def on_worker_fork(&block) # end def after_worker_fork(&block) @options[:after_worker_fork] ||= [] - @options[:after_worker_fork] = block + @options[:after_worker_fork] << block end alias_method :after_worker_boot, :after_worker_fork diff --git a/test/test_config.rb b/test/test_config.rb index d4e2443661..2052cc7079 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -363,16 +363,31 @@ def test_silence_single_worker_warning_overwrite def assert_run_hooks(hook_name, options = {}) configured_with = options[:configured_with] || hook_name + # test single, not an array + messages = [] + conf = Puma::Configuration.new + conf.options[hook_name] = -> (a) { + messages << "#{hook_name} is called with #{a}" + } + + conf.run_hooks hook_name, 'ARG', Puma::Events.strings + assert_equal messages, ["#{hook_name} is called with ARG"] + + # test multiple messages = [] conf = Puma::Configuration.new do |c| c.send(configured_with) do |a| - messages << "#{hook_name} is called with #{a}" + messages << "#{hook_name} is called with #{a} one time" + end + + c.send(configured_with) do |a| + messages << "#{hook_name} is called with #{a} a second time" end end conf.load conf.run_hooks hook_name, 'ARG', Puma::Events.strings - assert_equal messages, ["#{hook_name} is called with ARG"] + assert_equal messages, ["#{hook_name} is called with ARG one time", "#{hook_name} is called with ARG a second time"] end end