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
Conversation
fixes what seems to be a simple typo, now it behaves like expected
Tests would be great IMHO! Seeing existing tests did not catch this. |
Alright, I will give it a shot and add a test |
A suggestion, a change to
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}_1"
end
c.send(configured_with) do |a|
messages << "#{hook_name} is called with #{a}_2"
end
end
conf.load
conf.run_hooks hook_name, 'ARG', Puma::Events.strings
assert_equal messages, ["#{hook_name} is called with ARG_1", "#{hook_name} is called with ARG_2"]
end |
ahh thanks @MSP-Greg, I just pushed my updated test, just checking that multiple blocks can be run and one without an argument, too. I can change it to your version or keep it like this, I don't have a strong opinion here. |
Parts of the code allow for either an array or a single object, normally a block, but it's always converted to an array. I thought testing for both might be a good idea, which is why I had two asserts (one for a single block, one for two). The code to convert an object to an array is in |
thanks to MSP-Greg in puma#2690 (comment)
7e6306d
to
e0ec29e
Compare
alright, I updated the test based on your comment, just a small rewording :-) Didn't knew it is allowed/expected to manually set hooks like |
Part of the problem with API's is one could spend a month defining what is and isn't allowed. But, since the code in JFYI, a while ago I made a change to the API that I thought wouldn't cause an issue. It broke the code in a repo that needed a server for their CI, and they were starting Puma within code by creating a |
Yeah, it will be done if it can be done ;-) I think it is interesting that puma is not allowing to set multiple |
I think we set a speed record with this PR... 🚀 |
* 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)
fixes what seems to be a simple typo, now it behaves like expected
Do you think any test is needed for it?