about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-09 03:39:03 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-09 03:41:25 +0000
commit71716672752e573ff15002aaefd6e8ba8c6b6cb6 (patch)
tree6812276bfbb7dc842ffa5a9a46a8b49243a373cb /t
parent9d80b009a3cb795530ad23263f4eb525880e79dc (diff)
downloadunicorn-71716672752e573ff15002aaefd6e8ba8c6b6cb6.tar.gz
Since modern machines have more memory these days and
clients are sending more data, avoiding potentially slow
filesystem operations for larger uploads can be useful
for some applications.
Diffstat (limited to 't')
-rwxr-xr-xt/t0116-client_body_buffer_size.sh80
-rw-r--r--t/t0116.ru16
2 files changed, 96 insertions, 0 deletions
diff --git a/t/t0116-client_body_buffer_size.sh b/t/t0116-client_body_buffer_size.sh
new file mode 100755
index 0000000..c9e17c7
--- /dev/null
+++ b/t/t0116-client_body_buffer_size.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+. ./test-lib.sh
+t_plan 12 "client_body_buffer_size settings"
+
+t_begin "setup and start" && {
+        unicorn_setup
+        rtmpfiles unicorn_config_tmp one_meg
+        dd if=/dev/zero bs=1M count=1 of=$one_meg
+        cat >> $unicorn_config <<EOF
+after_fork do |server, worker|
+  File.open("$fifo", "wb") { |fp| fp.syswrite "START" }
+end
+EOF
+        cat $unicorn_config > $unicorn_config_tmp
+        echo client_body_buffer_size 0 >> $unicorn_config
+        unicorn -D -c $unicorn_config t0116.ru
+        unicorn_wait_start
+        fs_class=Unicorn::TmpIO
+        mem_class=StringIO
+
+        test x"$(cat $fifo)" = xSTART
+}
+
+t_begin "class for a zero-byte file should be StringIO" && {
+        > $tmp
+        test xStringIO = x"$(curl -T $tmp -sSf http://$listen/input_class)"
+}
+
+t_begin "class for a 1 byte file should be filesystem-backed" && {
+        echo > $tmp
+        test x$fs_class = x"$(curl -T $tmp -sSf http://$listen/tmp_class)"
+}
+
+t_begin "reload with default client_body_buffer_size" && {
+        mv $unicorn_config_tmp $unicorn_config
+        kill -HUP $unicorn_pid
+        test x"$(cat $fifo)" = xSTART
+}
+
+t_begin "class for a 1 byte file should be memory-backed" && {
+        echo > $tmp
+        test x$mem_class = x"$(curl -T $tmp -sSf http://$listen/tmp_class)"
+}
+
+t_begin "class for a random blob file should be filesystem-backed" && {
+        resp="$(curl -T random_blob -sSf http://$listen/tmp_class)"
+        test x$fs_class = x"$resp"
+}
+
+t_begin "one megabyte file should be filesystem-backed" && {
+        resp="$(curl -T $one_meg -sSf http://$listen/tmp_class)"
+        test x$fs_class = x"$resp"
+}
+
+t_begin "reload with a big client_body_buffer_size" && {
+        echo "client_body_buffer_size(1024 * 1024)" >> $unicorn_config
+        kill -HUP $unicorn_pid
+        test x"$(cat $fifo)" = xSTART
+}
+
+t_begin "one megabyte file should be memory-backed" && {
+        resp="$(curl -T $one_meg -sSf http://$listen/tmp_class)"
+        test x$mem_class = x"$resp"
+}
+
+t_begin "one megabyte + 1 byte file should be filesystem-backed" && {
+        echo >> $one_meg
+        resp="$(curl -T $one_meg -sSf http://$listen/tmp_class)"
+        test x$fs_class = x"$resp"
+}
+
+t_begin "killing succeeds" && {
+        kill $unicorn_pid
+}
+
+t_begin "check stderr" && {
+        check_stderr
+}
+
+t_done
diff --git a/t/t0116.ru b/t/t0116.ru
new file mode 100644
index 0000000..fab5fce
--- /dev/null
+++ b/t/t0116.ru
@@ -0,0 +1,16 @@
+#\ -E none
+use Rack::ContentLength
+use Rack::ContentType, 'text/plain'
+app = lambda do |env|
+  input = env['rack.input']
+  case env["PATH_INFO"]
+  when "/tmp_class"
+    body = input.instance_variable_get(:@tmp).class.name
+  when "/input_class"
+    body = input.class.name
+  else
+    return [ 500, {}, [] ]
+  end
+  [ 200, {}, [ body ] ]
+end
+run app