From bcac99b8cdcd0f32c4720d822d3049e3426f6cd3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 30 Oct 2013 20:24:58 +0000 Subject: implement before_exec hook This allows modifying the command-line (as an array) passed to Kernel#exec, as well as running anything necessary. --- test/test_server.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test') diff --git a/test/test_server.rb b/test/test_server.rb index 2cfee09..6059e03 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -655,4 +655,42 @@ class TestServer < Testcase assert_nil c.wait(1) assert_nil c.read(666) end + + def test_before_exec + err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1] + ru = lambda { |e| [ 200, {'Content-Length'=>'2' }, %w(OK) ] } + tmp = tmpfile(%w(exec .pid)) + x = "echo $$ >> #{tmp.path}" + pid = mkserver(cfg) do + cfg.instance_eval do + app(:rack, ru) { listen "#{host}:#{port}" } + before_exec do |exec_cmd| + exec_cmd.replace(%W(/bin/sh -c #{x})) + end + stderr_path err.path + end + end + + # did we start properly? + Net::HTTP.start(host, port) do |http| + assert_equal "OK", http.request(Net::HTTP::Get.new("/")).body + end + + Process.kill(:USR2, pid) + Timeout.timeout(30) { sleep(0.01) until tmp.size > 0 } + buf = tmp.read + assert_match %r{\A\d+}, buf + exec_pid = buf.to_i + poke_until_dead exec_pid + + # ensure it recovered + Net::HTTP.start(host, port) do |http| + assert_equal "OK", http.request(Net::HTTP::Get.new("/")).body + end + assert_match %r{reaped}, err.read + err.truncate(0) + ensure + tmp.close! + quit_wait(pid) + end end -- cgit v1.2.3-24-ge0c7