From 602432714cd436b6f255e6ba6bc6fffbf5eca051 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 30 Oct 2013 21:59:37 +0000 Subject: remove arity enforcement for atfork_* hooks It's usually given as a block, so Ruby won't care about arity there. Users will get the worker ID number as the first arg, making it possible to isolate some things to certain processes (e.g. for A/B testing). --- test/test_server.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test') diff --git a/test/test_server.rb b/test/test_server.rb index 6059e03..e6ddefc 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -440,6 +440,51 @@ class TestServer < Testcase quit_wait(pid) end + def test_mp_hooks_worker_nr + err = @err + out = tmpfile(%w(mp_hooks .out)) + cfg = Yahns::Config.new + host, port = @srv.addr[3], @srv.addr[1] + cfg.instance_eval do + ru = lambda {|_|x="#$$";[200,{'Content-Length'=>x.size.to_s },[x]]} + GTL.synchronize { + app(:rack, ru) { + listen "#{host}:#{port}" + persistent_connections false + } + worker_processes(1) do + atfork_child { |nr| puts "af.#{nr} #$$ worker is running" } + atfork_prepare { |nr| puts "af.#{nr} #$$ parent about to spawn" } + atfork_parent { |nr| puts "af.#{nr} #$$ this is probably not useful" } + end + } + stderr_path err.path + stdout_path out.path + end + pid = mkserver(cfg) + c = get_tcp_client(host, port) + c.write("GET / HTTP/1.0\r\nHost: example.com\r\n\r\n") + buf = Timeout.timeout(10) { c.read } + c.close + head, body = buf.split(/\r\n\r\n/) + assert_match(/200 OK/, head) + assert_match(/\A\d+\z/, body) + worker_pid = body.to_i + lines = out.readlines.map!(&:chomp!) + out.close! + + assert_equal 3, lines.size + assert_equal("af.0 #{pid} parent about to spawn", lines.shift) + + # child/parent ordering is not guaranteed + assert_equal 1, + lines.grep(/\Aaf\.0 #{pid} this is probably not useful\z/).size + assert_equal 1, + lines.grep(/\Aaf\.0 #{worker_pid} worker is running\z/).size + ensure + quit_wait(pid) + end + def test_pidfile_usr2 tmpdir = Dir.mktmpdir pidf = "#{tmpdir}/pid" -- cgit v1.2.3-24-ge0c7