diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-07-16 01:13:33 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-07-16 01:13:33 -0700 |
commit | 2e913054b36848a05f7ba06c3accbe164c666708 (patch) | |
tree | 3dbac8d2be3f7ba7a00cd23fff146c40e0a3d747 /test/unit/test_tee_input.rb | |
parent | a0f2c4514e969d0a127227201cbdb8e57f71df63 (diff) | |
download | unicorn-2e913054b36848a05f7ba06c3accbe164c666708.tar.gz |
This simplifies chunked_reader substantially with a slight increase in tee_input complexity. This is beneficial because chunked_reader is more complex to begin with and more likely to experience correctness issues.
Diffstat (limited to 'test/unit/test_tee_input.rb')
-rw-r--r-- | test/unit/test_tee_input.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb new file mode 100644 index 0000000..a6c61e6 --- /dev/null +++ b/test/unit/test_tee_input.rb @@ -0,0 +1,66 @@ +# encoding: binary +require 'test/unit' +require 'digest/sha1' +require 'unicorn' + +class TestTeeInput < Test::Unit::TestCase + + def setup + @rs = $/ + @env = {} + @rd, @wr = IO.pipe + @rd.sync = @wr.sync = true + @start_pid = $$ + end + + def teardown + return if $$ != @start_pid + $/ = @rs + @rd.close rescue nil + @wr.close rescue nil + begin + Process.wait + rescue Errno::ECHILD + break + end while true + end + + def test_gets_long + ti = Unicorn::TeeInput.new(@rd, nil, "hello") + status = line = nil + pid = fork { + @rd.close + 3.times { @wr.write("ffff" * 4096) } + @wr.write "#$/foo#$/" + @wr.close + } + @wr.close + assert_nothing_raised { line = ti.gets } + assert_equal(4096 * 4 * 3 + 5 + $/.size, line.size) + assert_equal("hello" << ("ffff" * 4096 * 3) << "#$/", line) + assert_nothing_raised { line = ti.gets } + assert_equal "foo#$/", line + assert_nil ti.gets + assert_nothing_raised { pid, status = Process.waitpid2(pid) } + assert status.success? + end + + def test_gets_short + ti = Unicorn::TeeInput.new(@rd, nil, "hello") + status = line = nil + pid = fork { + @rd.close + @wr.write "#$/foo" + @wr.close + } + @wr.close + assert_nothing_raised { line = ti.gets } + assert_equal("hello#$/", line) + assert_nothing_raised { line = ti.gets } + assert_equal "foo", line + assert_nil ti.gets + assert_nothing_raised { pid, status = Process.waitpid2(pid) } + assert status.success? + end + +end |