several response body#close fixes
[rainbows.git] / t / t0034-pipelined-pipe-response.sh
blob8346af92bb6fbd28b14e25f8eae21c092797fea8
1 #!/bin/sh
2 . ./test-lib.sh
4 t_plan 6 "pipelined pipe response for $model"
6 t_begin "setup and startup" && {
7 rtmpfiles err out dd_fifo
8 rainbows_setup $model
10 # can't load Rack::Lint here since it clobbers body#to_path
11 rainbows -E none -D fast-pipe-response.ru -c $unicorn_config
12 rainbows_wait_start
15 t_begin "read random blob sha1" && {
16 random_blob_sha1=$(rsha1 < random_blob)
19 script='
20 require "digest/sha1"
21 require "kcar"
22 $stdin.binmode
23 expect = ENV["random_blob_sha1"]
24 kcar = Kcar::Response.new($stdin, {})
25 3.times do
26 nr = 0
27 status, headers, body = kcar.rack
28 dig = Digest::SHA1.new
29 body.each { |buf| dig << buf ; nr += buf.size }
30 sha1 = dig.hexdigest
31 sha1 == expect or abort "mismatch: sha1=#{sha1} != expect=#{expect}"
32 body.close
33 end
34 $stdout.syswrite("ok\n")
37 t_begin "staggered pipeline of 3 HTTP requests" && {
38 req='GET /random_blob HTTP/1.1\r\nHost: example.com\r\n'
39 rm -f $ok
41 export random_blob_sha1
42 $RUBY -e "$script" < $fifo >> $ok &
43 printf "$req"'X-Req:0\r\n\r\n'
44 exec 6>&1
46 dd bs=16384 count=1
47 printf "$req" >&6
48 dd bs=16384 count=1
49 printf 'X-Req:1\r\n\r\n' >&6
50 dd bs=16384 count=1
51 printf "$req" >&6
52 dd bs=16384 count=1
53 printf 'X-Req:2\r\n' >&6
54 dd bs=16384 count=1
55 printf 'Connection: close\r\n\r' >&6
56 dd bs=16384 count=1
57 printf '\n' >&6
58 cat
59 ) < $dd_fifo > $fifo &
60 wait
61 echo ok >> $ok
62 ) | socat - TCP:$listen > $dd_fifo
63 test 2 -eq $(grep '^ok$' $ok |wc -l)
66 t_begin "pipeline 3 HTTP requests" && {
67 rm -f $ok
68 req='GET /random_blob HTTP/1.1\r\nHost: example.com\r\n'
69 req="$req"'\r\n'"$req"'\r\n'"$req"
70 req="$req"'Connection: close\r\n\r\n'
72 export random_blob_sha1
73 $RUBY -e "$script" < $fifo >> $ok &
74 printf "$req"
75 wait
76 echo ok >> $ok
77 ) | socat - TCP:$listen > $fifo
78 test 2 -eq $(grep '^ok$' $ok |wc -l)
81 t_begin "shutdown server" && {
82 kill -QUIT $rainbows_pid
85 t_begin "check stderr" && check_stderr
87 t_done