ensure client aborted file/stream response bodies are closed
[rainbows.git] / t / t0021-sendfile-wrap-to_path.sh
blob6baa89061e6eac17fd2741b164c8fc0d4fe7307e
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 10 "sendfile wrap body response for $model"
14 t_begin "setup and startup" && {
15 rtmpfiles out err http_fifo sub_ok
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 export fifo
22 rainbows -E none -D file-wrap-to_path.ru -c $unicorn_config
23 rainbows_wait_start
26 t_begin "read random blob sha1" && {
27 random_blob_sha1=$(rsha1 < random_blob)
30 t_begin "start FIFO reader" && {
31 cat $fifo > $out &
34 t_begin "single request matches" && {
35 sha1=$(curl -sSfv 2> $err http://$listen/random_blob | rsha1)
36 test -n "$sha1"
37 test x"$sha1" = x"$random_blob_sha1"
40 t_begin "body.close called" && {
41 wait # for cat $fifo
42 grep CLOSING $out || die "body.close not logged"
45 t_begin "start FIFO reader for abortive request" && {
46 cat $fifo > $out &
49 t_begin "send abortive request" && {
51 printf 'GET /random_blob\r\n'
52 dd bs=4096 count=1 < $http_fifo >/dev/null
53 echo ok > $ok
54 ) | socat - TCP:$listen > $http_fifo || :
55 test xok = x$(cat $ok)
58 t_begin "body.close called for aborted request" && {
59 wait # for cat $fifo
60 grep CLOSING $out || die "body.close not logged"
63 t_begin "shutdown server" && {
64 kill -QUIT $rainbows_pid
67 t_begin "check stderr" && check_stderr
69 t_done