Rainbows! 0.96.0 - range support
[rainbows.git] / t / t0020-large-sendfile-response.sh
blob18b0bf547a9adcfe2ee8dc978dc4a15fe8793762
1 #!/bin/sh
2 . ./test-lib.sh
3 test -r random_blob || die "random_blob required, run with 'make $0'"
4 case $RUBY_ENGINE in
5 ruby) ;;
6 *)
7 t_info "skipping $T since it can't load the sendfile gem, yet"
8 exit 0
9 ;;
10 esac
12 t_plan 12 "large sendfile response for $model"
14 t_begin "setup and startup" && {
15 rtmpfiles curl_out a b c slow_a slow_b
16 rainbows_setup $model
17 echo 'require "sendfile"' >> $unicorn_config
18 echo 'def (::IO).copy_stream(*x); abort "NO"; end' >> $unicorn_config
20 # can't load Rack::Lint here since it clobbers body#to_path
21 rainbows -E none -D large-file-response.ru -c $unicorn_config
22 rainbows_wait_start
25 t_begin "read random blob sha1" && {
26 random_blob_sha1=$(rsha1 < random_blob)
27 three_sha1=$(cat random_blob random_blob random_blob | rsha1)
30 t_begin "send keepalive HTTP/1.1 requests in parallel" && {
31 for i in $a $b $c $slow_a $slow_b
33 curl -sSf http://$listen/random_blob \
34 http://$listen/random_blob \
35 http://$listen/random_blob | rsha1 > $i &
36 done
37 wait
38 for i in $a $b $c $slow_a $slow_b
40 test x$(cat $i) = x$three_sha1
41 done
44 t_begin "send a batch of abortive HTTP/1.1 requests in parallel" && {
45 for i in $a $b $c $slow_a $slow_b
47 rm -f $i
49 curl -sSf --max-time 2 --limit-rate 1K \
50 http://$listen/random_blob >/dev/null || echo ok > $i
51 ) &
52 done
53 wait
56 t_begin "all requests timed out" && {
57 for i in $a $b $c $slow_a $slow_b
59 test x$(cat $i) = xok
60 done
63 s='$NF ~ /worker_connections=[0-9]+/{gsub(/[^0-9]/,"",$3); print $3; exit}'
64 t_begin "check proc to ensure file is closed properly (Linux only)" && {
65 worker_pid=$(awk "$s" < $r_err)
66 test -n "$worker_pid"
67 if test -d /proc/$worker_pid/fd
68 then
69 if ls -l /proc/$worker_pid/fd | grep random_blob
70 then
71 t_info "random_blob file is open ($model)"
73 else
74 t_info "/proc/$worker_pid/fd not found"
78 t_begin "send a bunch of HTTP/1.1 requests in parallel" && {
80 curl -sSf --limit-rate 5M http://$listen/random_blob | \
81 rsha1 > $slow_a
82 ) &
84 curl -sSf --limit-rate 6M http://$listen/random_blob | \
85 rsha1 > $slow_b
86 ) &
87 for i in $a $b $c
90 curl -sSf http://$listen/random_blob | rsha1 > $i
91 ) &
92 done
93 wait
94 for i in $a $b $c $slow_a $slow_b
96 test x$(cat $i) = x$random_blob_sha1
97 done
100 # this was a problem during development
101 t_begin "HTTP/1.0 test" && {
102 sha1=$( (curl -0 -sSf http://$listen/random_blob &&
103 echo ok >$ok) | rsha1)
104 test $sha1 = $random_blob_sha1
105 test xok = x$(cat $ok)
108 t_begin "HTTP/0.9 test" && {
110 printf 'GET /random_blob\r\n'
111 rsha1 < $fifo > $tmp &
112 wait
113 echo ok > $ok
114 ) | socat - TCP:$listen > $fifo
115 test $(cat $tmp) = $random_blob_sha1
116 test xok = x$(cat $ok)
119 t_begin "check proc to ensure file is closed properly (Linux only)" && {
120 worker_pid=$(awk "$s" < $r_err)
121 test -n "$worker_pid"
122 if test -d /proc/$worker_pid/fd
123 then
124 if ls -l /proc/$worker_pid/fd | grep random_blob
125 then
126 t_info "random_blob file is open ($model)"
128 else
129 t_info "/proc/$worker_pid/fd not found"
133 t_begin "shutdown server" && {
134 kill -QUIT $rainbows_pid
137 dbgcat r_err
139 t_begin "check stderr" && check_stderr
141 t_done