about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/rainbows/dev_fd_response.rb3
-rw-r--r--t/kgio-pipe-response.ru10
-rwxr-xr-xt/t0035-kgio-pipe-response.sh70
3 files changed, 82 insertions, 1 deletions
diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb
index 7f70b8e..ec09d1e 100644
--- a/lib/rainbows/dev_fd_response.rb
+++ b/lib/rainbows/dev_fd_response.rb
@@ -54,7 +54,8 @@ class Rainbows::DevFdResponse < Struct.new(:app)
       # we need to make sure our pipe output is Fiber-compatible
       case env["rainbows.model"]
       when :FiberSpawn, :FiberPool, :RevFiberSpawn
-        io = Rainbows::Fiber::IO.new(io,::Fiber.current)
+        io.respond_to?(:wait_readable) or
+          io = Rainbows::Fiber::IO.new(io)
       when :Revactor
         io = Rainbows::Revactor::Proxy.new(io)
       end
diff --git a/t/kgio-pipe-response.ru b/t/kgio-pipe-response.ru
new file mode 100644
index 0000000..edd2aac
--- /dev/null
+++ b/t/kgio-pipe-response.ru
@@ -0,0 +1,10 @@
+# must be run without Rack::Lint since that clobbers to_path
+use Rainbows::DevFdResponse
+run(lambda { |env|
+  [ 200,
+    {
+      'Content-Length' => ::File.stat('random_blob').size.to_s,
+      'Content-Type' => 'application/octet-stream',
+    },
+    Rainbows::Fiber::IO::Pipe.popen('cat random_blob', 'rb') ]
+})
diff --git a/t/t0035-kgio-pipe-response.sh b/t/t0035-kgio-pipe-response.sh
new file mode 100755
index 0000000..97c3f2a
--- /dev/null
+++ b/t/t0035-kgio-pipe-response.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+. ./test-lib.sh
+test -r random_blob || die "random_blob required, run with 'make $0'"
+case $model in
+*Fiber* ) ;;
+*)
+        t_info "skipping $T since it's not compatible with $model"
+        exit 0
+        ;;
+esac
+
+t_plan 10 "fast Kgio pipe response for $model"
+
+t_begin "setup and startup" && {
+        rtmpfiles err out
+        rainbows_setup $model
+        rainbows -E none -D kgio-pipe-response.ru -c $unicorn_config
+        rainbows_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 "single request matches" && {
+        sha1=$(curl -sSfv 2> $err http://$listen/ | rsha1)
+        test -n "$sha1"
+        test x"$sha1" = x"$random_blob_sha1"
+}
+
+t_begin "Content-Length header preserved in response" && {
+        grep "^< Content-Length:" $err
+}
+
+t_begin "send three keep-alive requests" && {
+        sha1=$(curl -vsSf 2> $err \
+               http://$listen/ http://$listen/ http://$listen/ | rsha1)
+        test -n "$sha1"
+        test x"$sha1" = x"$three_sha1"
+}
+
+t_begin "ensure responses were all keep-alive" && {
+        test 3 -eq $(grep '< Connection: keep-alive' < $err | wc -l)
+}
+
+t_begin "HTTP/1.0 test" && {
+        sha1=$(curl -0 -v 2> $err -sSf http://$listen/ | rsha1)
+        test $sha1 = $random_blob_sha1
+        grep '< Connection: close' < $err
+}
+
+t_begin "HTTP/0.9 test" && {
+        (
+                printf 'GET /\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
+}
+
+t_begin "check stderr" && check_stderr
+
+t_done