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