Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow multiple after_worker_fork hooks #2690

Merged
merged 2 commits into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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