thread_timeout: document Thread.pass usage
[rainbows.git] / t / t0034-pipelined-pipe-response.sh
blob6dff9ad1341cb7f073c029fe25201434ea702e4e
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 |i|
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 warn "[#{i}] nr: #{nr}"
32 sha1 == expect or abort "mismatch: sha1=#{sha1} != expect=#{expect}"
33 body.close
34 end
35 $stdout.syswrite("ok\n")
38 t_begin "staggered pipeline of 3 HTTP requests" && {
39 req='GET /random_blob HTTP/1.1\r\nHost: example.com\r\n'
40 rm -f $ok
42 export random_blob_sha1
43 $RUBY -e "$script" < $fifo >> $ok &
44 printf "$req"'X-Req:0\r\n\r\n'
45 exec 6>&1
47 dd bs=16384 count=1
48 printf "$req" >&6
49 dd bs=16384 count=1
50 printf 'X-Req:1\r\n\r\n' >&6
51 dd bs=16384 count=1
52 printf "$req" >&6
53 dd bs=16384 count=1
54 printf 'X-Req:2\r\n' >&6
55 dd bs=16384 count=1
56 printf 'Connection: close\r\n\r' >&6
57 dd bs=16384 count=1
58 printf '\n' >&6
59 cat
60 ) < $dd_fifo > $fifo &
61 wait
62 echo ok >> $ok
63 ) | socat - TCP:$listen > $dd_fifo
64 test 2 -eq $(grep '^ok$' $ok |wc -l)
67 t_begin "pipeline 3 HTTP requests" && {
68 rm -f $ok
69 req='GET /random_blob HTTP/1.1\r\nHost: example.com\r\n'
70 req="$req"'\r\n'"$req"'\r\n'"$req"
71 req="$req"'Connection: close\r\n\r\n'
73 export random_blob_sha1
74 $RUBY -e "$script" < $fifo >> $ok &
75 printf "$req"
76 wait
77 echo ok >> $ok
78 ) | socat - TCP:$listen > $fifo
79 test 2 -eq $(grep '^ok$' $ok |wc -l)
82 t_begin "shutdown server" && {
83 kill -QUIT $rainbows_pid
86 t_begin "check stderr" && check_stderr
88 t_done