From 8175a52c67fb9dfc9c04a7b0597b680699f43deb Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 28 Jun 2010 08:06:32 +0000 Subject: add preliminary sendfile (1.0.0) gem support This still needs work and lots of cleanup, but the basics are there. The sendfile 1.0.0 RubyGem is now safe to use under MRI 1.8, and is superior to current (1.9.2-preview3) versions of IO.copy_stream for static files in that it supports more platforms and doesn't truncate large files on 32-bit platforms. --- t/t0020-large-sendfile-response.sh | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 t/t0020-large-sendfile-response.sh (limited to 't/t0020-large-sendfile-response.sh') diff --git a/t/t0020-large-sendfile-response.sh b/t/t0020-large-sendfile-response.sh new file mode 100755 index 0000000..822a23f --- /dev/null +++ b/t/t0020-large-sendfile-response.sh @@ -0,0 +1,72 @@ +#!/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 "large sendfile response for $model" + +t_begin "setup and startup" && { + rtmpfiles curl_out a b c + rainbows_setup $model 2 + + # FIXME: allow "require 'sendfile'" to work in $unicorn_config + RUBYOPT="-rsendfile" + export RUBYOPT + + # can't load Rack::Lint here since it clobbers body#to_path + rainbows -E none -D large-file-response.ru -c $unicorn_config + rainbows_wait_start +} + +t_begin "read random blob sha1" && { + random_blob_sha1=$(rsha1 < random_blob) +} + +t_begin "send a series of HTTP/1.1 requests in parallel" && { + for i in $a $b $c + do + ( + curl -sSf http://$listen/random_blob | rsha1 > $i + ) & + done + wait + for i in $a $b $c + do + test x$(cat $i) = x$random_blob_sha1 + done +} + +# this was a problem during development +t_begin "HTTP/1.0 test" && { + sha1=$( (curl -0 -sSfv http://$listen/random_blob && + echo ok >$ok) | rsha1) + test $sha1 = $random_blob_sha1 + test xok = x$(cat $ok) +} + +t_begin "HTTP/0.9 test" && { + ( + printf 'GET /random_blob\r\n' + rsha1 < $fifo > $tmp & + wait + echo ok > $ok + ) | socat - TCP:$listen > $fifo + test $(cat $tmp) = $random_blob_sha1 + test xok = x$(cat $ok) +} + +t_begin "shutdown server" && { + kill -QUIT $rainbows_pid +} + +dbgcat r_err + +t_begin "check stderr" && check_stderr + +t_done -- cgit v1.2.3-24-ge0c7