Skip to content

Commit

Permalink
allow multiple after_worker_fork hooks (puma#2690)
Browse files Browse the repository at this point in the history
* allow multiple after_worker_fork hooks

fixes what seems to be a simple typo, now it behaves like expected

* update tests for multiple hook calls

thanks to MSP-Greg in puma#2690 (comment)
  • Loading branch information
doits authored and JuanitoFatas committed Sep 9, 2022
1 parent 8ab9a02 commit cb3eb19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/puma/dsl.rb
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions test/test_config.rb
Expand Up @@ -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

Expand Down

0 comments on commit cb3eb19

Please sign in to comment.