about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-10-30 20:24:58 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-31 05:04:33 +0000
commitbcac99b8cdcd0f32c4720d822d3049e3426f6cd3 (patch)
treea0b4e5cdf9388d4c5a6409106445f3c2678b27df /test
parentf9f8e25fd985b7a063da8070f3b3782b1a64a86c (diff)
downloadyahns-bcac99b8cdcd0f32c4720d822d3049e3426f6cd3.tar.gz
This allows modifying the command-line (as an array) passed to
Kernel#exec, as well as running anything necessary.
Diffstat (limited to 'test')
-rw-r--r--test/test_server.rb38
1 files changed, 38 insertions, 0 deletions
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