stream_response_epoll: our most "special" concurrency option yet
[rainbows.git] / t / t0020-large-sendfile-response.sh
bloba8bc8e241ff15d01aeda4bdcc2357fc39569254e
1 #!/bin/sh
2 . ./test-lib.sh
3 skip_models StreamResponseEpoll
4 test -r random_blob || die "random_blob required, run with 'make $0'"
5 case $RUBY_ENGINE in
6 ruby) ;;
7 *)
8 t_info "skipping $T since it can't load the sendfile gem, yet"
9 exit 0
11 esac
13 t_plan 12 "large sendfile response for $model"
15 t_begin "setup and startup" && {
16 rtmpfiles curl_out a b c slow_a slow_b
17 rainbows_setup $model
18 echo 'require "sendfile"' >> $unicorn_config
19 echo 'def (::IO).copy_stream(*x); abort "NO"; end' >> $unicorn_config
21 # can't load Rack::Lint here since it clobbers body#to_path
22 rainbows -E none -D large-file-response.ru -c $unicorn_config
23 rainbows_wait_start
26 t_begin "read random blob sha1" && {
27 random_blob_sha1=$(rsha1 < random_blob)
28 three_sha1=$(cat random_blob random_blob random_blob | rsha1)
31 t_begin "send keepalive HTTP/1.1 requests in parallel" && {
32 for i in $a $b $c $slow_a $slow_b
34 curl -sSf http://$listen/random_blob \
35 http://$listen/random_blob \
36 http://$listen/random_blob | rsha1 > $i &
37 done
38 wait
39 for i in $a $b $c $slow_a $slow_b
41 test x$(cat $i) = x$three_sha1
42 done
45 t_begin "send a batch of abortive HTTP/1.1 requests in parallel" && {
46 for i in $a $b $c $slow_a $slow_b
48 rm -f $i
50 curl -sSf --max-time 2 --limit-rate 1K \
51 http://$listen/random_blob >/dev/null || echo ok > $i
52 ) &
53 done
54 wait
57 t_begin "all requests timed out" && {
58 for i in $a $b $c $slow_a $slow_b
60 test x$(cat $i) = xok
61 done
64 s='$NF ~ /worker_connections=[0-9]+/{gsub(/[^0-9]/,"",$3); print $3; exit}'
65 t_begin "check proc to ensure file is closed properly (Linux only)" && {
66 worker_pid=$(awk "$s" < $r_err)
67 test -n "$worker_pid"
68 if test -d /proc/$worker_pid/fd
69 then
70 if ls -l /proc/$worker_pid/fd | grep random_blob
71 then
72 t_info "random_blob file is open ($model)"
74 else
75 t_info "/proc/$worker_pid/fd not found"
79 t_begin "send a bunch of HTTP/1.1 requests in parallel" && {
81 curl -sSf --limit-rate 5M http://$listen/random_blob | \
82 rsha1 > $slow_a
83 ) &
85 curl -sSf --limit-rate 6M http://$listen/random_blob | \
86 rsha1 > $slow_b
87 ) &
88 for i in $a $b $c
91 curl -sSf http://$listen/random_blob | rsha1 > $i
92 ) &
93 done
94 wait
95 for i in $a $b $c $slow_a $slow_b
97 test x$(cat $i) = x$random_blob_sha1
98 done
101 # this was a problem during development
102 t_begin "HTTP/1.0 test" && {
103 sha1=$( (curl -0 -sSf http://$listen/random_blob &&
104 echo ok >$ok) | rsha1)
105 test $sha1 = $random_blob_sha1
106 test xok = x$(cat $ok)
109 t_begin "HTTP/0.9 test" && {
111 printf 'GET /random_blob\r\n'
112 rsha1 < $fifo > $tmp &
113 wait
114 echo ok > $ok
115 ) | socat - TCP:$listen > $fifo
116 test $(cat $tmp) = $random_blob_sha1
117 test xok = x$(cat $ok)
120 t_begin "check proc to ensure file is closed properly (Linux only)" && {
121 worker_pid=$(awk "$s" < $r_err)
122 test -n "$worker_pid"
123 if test -d /proc/$worker_pid/fd
124 then
125 if ls -l /proc/$worker_pid/fd | grep random_blob
126 then
127 t_info "random_blob file is open ($model)"
129 else
130 t_info "/proc/$worker_pid/fd not found"
134 t_begin "shutdown server" && {
135 kill -QUIT $rainbows_pid
138 dbgcat r_err
140 t_begin "check stderr" && check_stderr
142 t_done