unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob a6c61e69599c7941cf63e906879b9494d2f6fee2 1515 bytes (raw)
$ git show v0.9.2:test/unit/test_tee_input.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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

git clone https://yhbt.net/unicorn.git