about summary refs log tree commit homepage
path: root/t/t0024-pipelined-sendfile-response.sh
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-25 09:28:22 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-26 09:23:49 +0000
commit052e2b3608071d9cd9d6b1d12f8cb69ac29124af (patch)
treed1c72552fd8ccc7dd5d3ad3a4dd76fbf68ebea72 /t/t0024-pipelined-sendfile-response.sh
parent84ac2eaa8bd16e44420abf660420698f76ad5473 (diff)
downloadrainbows-052e2b3608071d9cd9d6b1d12f8cb69ac29124af.tar.gz
With sendfile enabled, we must avoid writing headers (or normal,
non-file responses) while a file is deferred for sending.  This
means we must disable processing of new requests while a file
is deferred for sending and use the on_write_complete callback
less aggressively.
Diffstat (limited to 't/t0024-pipelined-sendfile-response.sh')
-rwxr-xr-xt/t0024-pipelined-sendfile-response.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/t/t0024-pipelined-sendfile-response.sh b/t/t0024-pipelined-sendfile-response.sh
new file mode 100755
index 0000000..2acc243
--- /dev/null
+++ b/t/t0024-pipelined-sendfile-response.sh
@@ -0,0 +1,67 @@
+#!/bin/sh
+. ./test-lib.sh
+
+case $model in
+EventMachine|NeverBlock)
+        t_info "skipping $T since it's not compatible with $model"
+        exit 0
+        ;;
+*) ;;
+esac
+
+t_plan 5 "pipelined sendfile response for $model"
+
+t_begin "setup and startup" && {
+        rtmpfiles err out
+        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
+        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)
+}
+
+script='
+require "digest/sha1"
+require "kcar"
+$stdin.binmode
+expect = ENV["random_blob_sha1"]
+kcar = Kcar::Response.new($stdin, {})
+3.times do
+        nr = 0
+        status, headers, body = kcar.rack
+        dig = Digest::SHA1.new
+        body.each { |buf| dig << buf ; nr += buf.size }
+        sha1 = dig.hexdigest
+        sha1 == expect or abort "mismatch: sha1=#{sha1} != expect=#{expect}"
+        body.close
+end
+$stdout.syswrite("ok\n")
+'
+
+t_begin "pipeline 3 HTTP requests" && {
+        req='GET /random_blob HTTP/1.1\r\nHost: example.com\r\n'
+        req="$req"'\r\n'"$req"'\r\n'"$req"
+        req="$req"'Connection: close\r\n\r\n'
+        (
+                export random_blob_sha1
+                $RUBY -e "$script" < $fifo >> $ok &
+                printf "$req"
+                wait
+                echo ok >> $ok
+        ) | socat - TCP:$listen > $fifo
+        test 2 -eq $(grep '^ok$' $ok |wc -l)
+}
+
+t_begin "shutdown server" && {
+        kill -QUIT $rainbows_pid
+}
+
+t_begin "check stderr" && check_stderr
+
+t_done