From 2e913054b36848a05f7ba06c3accbe164c666708 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 16 Jul 2009 01:13:33 -0700 Subject: move all #gets logic to tee_input out of chunked_reader 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. --- test/unit/test_tee_input.rb | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/unit/test_tee_input.rb (limited to 'test/unit/test_tee_input.rb') 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 -- cgit v1.2.3-24-ge0c7