diff options
Diffstat (limited to 't')
-rw-r--r-- | t/file-wrap-to_path.ru | 24 | ||||
-rw-r--r-- | t/t0021-sendfile-wrap-to_path.sh | 51 |
2 files changed, 75 insertions, 0 deletions
diff --git a/t/file-wrap-to_path.ru b/t/file-wrap-to_path.ru new file mode 100644 index 0000000..f12e08d --- /dev/null +++ b/t/file-wrap-to_path.ru @@ -0,0 +1,24 @@ +# must be run without Rack::Lint since that clobbers to_path +class Wrapper < Struct.new(:app) + def call(env) + status, headers, body = app.call(env) + body = Body.new(body) if body.respond_to?(:to_path) + [ status, headers, body ] + end + + class Body < Struct.new(:body) + def to_path + body.to_path + end + + def each(&block) + body.each(&block) + end + + def close + ::File.open(ENV['fifo'], 'wb') { |fp| fp.puts "CLOSING" } + end + end +end +use Wrapper +run Rack::File.new(Dir.pwd) 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 |