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