diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-10 09:53:52 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-10 09:53:52 +0000 |
commit | 59d3b3f6318a85e4d68592e1f7b992dd54832aa0 (patch) | |
tree | e459139efe531b108fe6b11648dd26d8c710ba19 | |
parent | bd6b2263869c271113577b88d526c7c2a6f1455d (diff) | |
download | zbatery-59d3b3f6318a85e4d68592e1f7b992dd54832aa0.tar.gz |
add additional tests for newish Rainbows! features
-rw-r--r-- | t/sha1-random-size.ru | 19 | ||||
-rwxr-xr-x | t/t0020-large-sendfile-response.sh | 141 | ||||
-rwxr-xr-x | t/t0103-rack-input-limit.sh | 61 |
3 files changed, 221 insertions, 0 deletions
diff --git a/t/sha1-random-size.ru b/t/sha1-random-size.ru new file mode 100644 index 0000000..f86d017 --- /dev/null +++ b/t/sha1-random-size.ru @@ -0,0 +1,19 @@ +# SHA1 checksum generator +require 'digest/sha1' +use Rack::ContentLength +cap = 16384 +app = lambda do |env| + /\A100-continue\z/i =~ env['HTTP_EXPECT'] and + return [ 100, {}, [] ] + digest = Digest::SHA1.new + input = env['rack.input'] + if buf = input.read(rand(cap)) + begin + raise "#{buf.size} > #{cap}" if buf.size > cap + digest.update(buf) + end while input.read(rand(cap), buf) + end + + [ 200, {'Content-Type' => 'text/plain'}, [ digest.hexdigest << "\n" ] ] +end +run app diff --git a/t/t0020-large-sendfile-response.sh b/t/t0020-large-sendfile-response.sh new file mode 100755 index 0000000..a69914f --- /dev/null +++ b/t/t0020-large-sendfile-response.sh @@ -0,0 +1,141 @@ +#!/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 12 "large sendfile response for $model" + +t_begin "setup and startup" && { + rtmpfiles curl_out a b c slow_a slow_b + zbatery_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 + zbatery -E none -D large-file-response.ru -c $unicorn_config + zbatery_wait_start +} + +t_begin "read random blob sha1" && { + random_blob_sha1=$(rsha1 < random_blob) + three_sha1=$(cat random_blob random_blob random_blob | rsha1) +} + +t_begin "send keepalive HTTP/1.1 requests in parallel" && { + for i in $a $b $c $slow_a $slow_b + do + curl -sSf http://$listen/random_blob \ + http://$listen/random_blob \ + http://$listen/random_blob | rsha1 > $i & + done + wait + for i in $a $b $c $slow_a $slow_b + do + test x$(cat $i) = x$three_sha1 + done +} + +t_begin "send a batch of abortive HTTP/1.1 requests in parallel" && { + for i in $a $b $c $slow_a $slow_b + do + rm -f $i + ( + curl -sSf --max-time 5 --limit-rate 1K \ + http://$listen/random_blob >/dev/null || echo ok > $i + ) & + done + wait +} + +t_begin "all requests timed out" && { + for i in $a $b $c $slow_a $slow_b + do + test x$(cat $i) = xok + done +} + +s='$NF ~ /worker_connections=[0-9]+/{gsub(/[^0-9]/,"",$3); print $3; exit}' +t_begin "check proc to ensure file is closed properly (Linux only)" && { + worker_pid=$(awk "$s" < $r_err) + test -n "$worker_pid" + if test -d /proc/$worker_pid/fd + then + if ls -l /proc/$worker_pid/fd | grep random_blob + then + t_info "random_blob file is open ($model)" + fi + else + t_info "/proc/$worker_pid/fd not found" + fi +} + +t_begin "send a bunch of HTTP/1.1 requests in parallel" && { + ( + curl -sSf --limit-rate 1M http://$listen/random_blob | \ + rsha1 > $slow_a + ) & + ( + curl -sSf --limit-rate 750K http://$listen/random_blob | \ + rsha1 > $slow_b + ) & + for i in $a $b $c + do + ( + curl -sSf http://$listen/random_blob | rsha1 > $i + ) & + done + wait + for i in $a $b $c $slow_a $slow_b + 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 -sSf 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 "check proc to ensure file is closed properly (Linux only)" && { + worker_pid=$(awk "$s" < $r_err) + test -n "$worker_pid" + if test -d /proc/$worker_pid/fd + then + if ls -l /proc/$worker_pid/fd | grep random_blob + then + t_info "random_blob file is open ($model)" + fi + else + t_info "/proc/$worker_pid/fd not found" + fi +} + +t_begin "shutdown server" && { + kill -QUIT $zbatery_pid +} + +dbgcat r_err + +t_begin "check stderr" && check_stderr + +t_done diff --git a/t/t0103-rack-input-limit.sh b/t/t0103-rack-input-limit.sh new file mode 100755 index 0000000..6b40544 --- /dev/null +++ b/t/t0103-rack-input-limit.sh @@ -0,0 +1,61 @@ +#!/bin/sh +. ./test-lib.sh +test -r random_blob || die "random_blob required, run with 'make $0'" +req_curl_chunked_upload_err_check + +t_plan 6 "rack.input client_max_body_size default" + +t_begin "setup and startup" && { + rtmpfiles curl_out curl_err cmbs_config + zbatery_setup $model + grep -v client_max_body_size < $unicorn_config > $cmbs_config + zbatery -D sha1-random-size.ru -c $cmbs_config + zbatery_wait_start +} + +t_begin "regular request" && { + rm -f $ok + curl -vsSf -T random_blob -H Expect: \ + http://$listen/ > $curl_out 2> $curl_err || > $ok + dbgcat curl_err + dbgcat curl_out + test -e $ok +} + +t_begin "chunked request" && { + rm -f $ok + curl -vsSf -T- < random_blob -H Expect: \ + http://$listen/ > $curl_out 2> $curl_err || > $ok + dbgcat curl_err + dbgcat curl_out + test -e $ok +} + +t_begin "default size sha1 chunked" && { + blob_sha1=3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3 + rm -f $ok + > $r_err + dd if=/dev/zero bs=1048576 count=1 | \ + curl -vsSf -T- -H Expect: \ + http://$listen/ > $curl_out 2> $curl_err + test "$(cat $curl_out)" = $blob_sha1 + dbgcat curl_err + dbgcat curl_out +} + +t_begin "default size sha1 content-length" && { + blob_sha1=3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3 + rm -f $ok + dd if=/dev/zero bs=1048576 count=1 of=$tmp + curl -vsSf -T $tmp -H Expect: \ + http://$listen/ > $curl_out 2> $curl_err + test "$(cat $curl_out)" = $blob_sha1 + dbgcat curl_err + dbgcat curl_out +} + +t_begin "shutdown" && { + kill $zbatery_pid +} + +t_done |