diff options
author | Eric Wong <e@80x24.org> | 2013-10-30 01:50:23 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-30 07:01:07 +0000 |
commit | f2f1687a63e594cb7929552e8a4501f227dba778 (patch) | |
tree | 9fd4e5702f2992a8ff754a91417f0749e6379ff7 | |
parent | f5e181e2c23b432163b1924b8325bd34db2ca5b0 (diff) | |
download | yahns-f2f1687a63e594cb7929552e8a4501f227dba778.tar.gz |
Different instances/ports of apps may want to point error output elsewhere.
-rw-r--r-- | test/test_server.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/test_server.rb b/test/test_server.rb index 934ae3e..47c6bd5 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -583,4 +583,42 @@ class TestServer < Testcase end end end + + def test_errors + tmpdir = Dir.mktmpdir + sock = "#{tmpdir}/sock" + err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1] + re = tmpfile(%w(rack .errors)) + ru = lambda { |e| + e["rack.errors"].write "INFO HIHI\n" + [ 200, {'Content-Length'=>'2' }, %w(OK) ] + } + cfg.instance_eval do + GTL.synchronize { + app(:rack, ru) { + listen "#{host}:#{port}" + errors re.path + } + app(:rack, ru) { listen sock } + } + stderr_path err.path + end + pid = mkserver(cfg) + Net::HTTP.start(host, port) do |http| + assert_equal "OK", http.request(Net::HTTP::Get.new("/")).body + end + assert_equal "INFO HIHI\n", re.read + + c = UNIXSocket.new(sock) + c.close_on_exec = true + c.write "GET /\r\n\r\n" + assert_equal c, c.wait(30) + assert_equal "OK", c.read + c.close + assert_match %r{INFO HIHI}, File.read(err.path) + ensure + re.close! + quit_wait(pid) + FileUtils.rm_rf(tmpdir) + end end |