about summary refs log tree commit homepage
path: root/t/t0021-sendfile-wrap-to_path.sh
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-19 10:10:06 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-19 17:04:37 -0700
commit60039518e03b0f1a0f530eefe008ebf72c55afe4 (patch)
treec31a8ff013634812ae71f7c935d309c652d5052a /t/t0021-sendfile-wrap-to_path.sh
parent0cd65fa1e01be369b270c72053cf21a3d6bcb45f (diff)
downloadrainbows-60039518e03b0f1a0f530eefe008ebf72c55afe4.tar.gz
Middlewares like Clogger may wrap Rack::File responses
with another body that responds to to_path and still
rely on #close to trigger an action (writing out the log
file).
Diffstat (limited to 't/t0021-sendfile-wrap-to_path.sh')
-rw-r--r--t/t0021-sendfile-wrap-to_path.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/t/t0021-sendfile-wrap-to_path.sh b/t/t0021-sendfile-wrap-to_path.sh
new file mode 100644
index 0000000..4ae5929
--- /dev/null
+++ b/t/t0021-sendfile-wrap-to_path.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+. ./test-lib.sh
+test -r random_blob || die "random_blob required, run with 'make $0'"
+case $RUBY_ENGINE in
+ruby) ;;
+*)
+        t_info "skipping $T since it can't load the sendfile gem, yet"
+        exit 0
+        ;;
+esac
+
+t_plan 7 "sendfile wrap body response for $model"
+
+t_begin "setup and startup" && {
+        rtmpfiles out err
+        rainbows_setup $model
+        echo 'require "sendfile"' >> $unicorn_config
+        echo 'def (::IO).copy_stream(*x); abort "NO"; end' >> $unicorn_config
+
+        # can't load Rack::Lint here since it clobbers body#to_path
+        export fifo
+        rainbows -E none -D file-wrap-to_path.ru -c $unicorn_config
+        rainbows_wait_start
+}
+
+t_begin "read random blob sha1" && {
+        random_blob_sha1=$(rsha1 < random_blob)
+}
+
+t_begin "start FIFO reader" && {
+        cat $fifo > $out &
+}
+
+t_begin "single request matches" && {
+        sha1=$(curl -sSfv 2> $err http://$listen/random_blob | rsha1)
+        test -n "$sha1"
+        test x"$sha1" = x"$random_blob_sha1"
+}
+
+t_begin "body.close called" && {
+        wait # for cat $fifo
+        grep CLOSING $out || die "body.close not logged"
+}
+
+t_begin "shutdown server" && {
+        kill -QUIT $rainbows_pid
+}
+
+t_begin "check stderr" && check_stderr
+
+t_done