about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-19 10:10:05 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-19 17:04:35 -0700
commit0cd65fa1e01be369b270c72053cf21a3d6bcb45f (patch)
tree7ae76d0860f740838faa9cb5172b100b7a58a35c /t
parented14b9bdbb35fa18dc283ba2d048a33d10759b2d (diff)
downloadrainbows-0cd65fa1e01be369b270c72053cf21a3d6bcb45f.tar.gz
Some middlewares such as Clogger rely on wrapping the body
having the close method called on it for logging.
Diffstat (limited to 't')
-rw-r--r--t/close-pipe-response.ru26
-rw-r--r--t/t0031-close-pipe-response.sh30
2 files changed, 56 insertions, 0 deletions
diff --git a/t/close-pipe-response.ru b/t/close-pipe-response.ru
new file mode 100644
index 0000000..96116d4
--- /dev/null
+++ b/t/close-pipe-response.ru
@@ -0,0 +1,26 @@
+# must be run without Rack::Lint since that clobbers to_path
+class CloseWrapper < Struct.new(:to_io)
+  def each(&block)
+    to_io.each(&block)
+  end
+
+  def close
+    ::File.open(ENV['fifo'], 'wb') do |fp|
+      fp.syswrite("CLOSING #{to_io}\n")
+      if to_io.respond_to?(:close) && ! to_io.closed?
+        to_io.close
+      end
+    end
+  end
+end
+use Rainbows::DevFdResponse
+run(lambda { |env|
+  body = 'hello world'
+  io = IO.popen("echo '#{body}'", 'rb')
+  [ 200,
+    {
+      'Content-Length' => (body.size + 1).to_s,
+      'Content-Type' => 'application/octet-stream',
+    },
+    CloseWrapper[io] ]
+})
diff --git a/t/t0031-close-pipe-response.sh b/t/t0031-close-pipe-response.sh
new file mode 100644
index 0000000..7439b5f
--- /dev/null
+++ b/t/t0031-close-pipe-response.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+. ./test-lib.sh
+
+t_plan 5 "close pipe response for $model"
+
+t_begin "setup and startup" && {
+        rtmpfiles err out
+        rainbows_setup $model
+        export fifo
+        rainbows -E none -D close-pipe-response.ru -c $unicorn_config
+        rainbows_wait_start
+}
+
+t_begin "single request matches" && {
+        cat $fifo > $out &
+        test x'hello world' = x"$(curl -sSfv 2> $err http://$listen/)"
+}
+
+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