diff options
Diffstat (limited to 't')
-rw-r--r-- | t/GNUmakefile | 8 | ||||
-rw-r--r-- | t/preread_input.ru | 17 | ||||
-rw-r--r-- | t/rails3-app/Gemfile | 2 | ||||
-rwxr-xr-x | t/t0003-working_directory.sh | 5 | ||||
-rwxr-xr-x | t/t0010-reap-logging.sh | 55 | ||||
-rw-r--r-- | t/t0011-active-unix-socket.sh | 79 | ||||
-rwxr-xr-x | t/t0303-rails3-alt-working_directory_config.ru.sh | 5 | ||||
-rwxr-xr-x | t/t9000-preread-input.sh | 48 | ||||
-rw-r--r-- | t/test-rails3.sh | 4 |
9 files changed, 209 insertions, 14 deletions
diff --git a/t/GNUmakefile b/t/GNUmakefile index e80c43a..8f2668c 100644 --- a/t/GNUmakefile +++ b/t/GNUmakefile @@ -17,6 +17,12 @@ endif RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))') export RUBY_ENGINE +isolate_libs := ../tmp/isolate/$(RUBY_ENGINE)-$(RUBY_VERSION).mk +$(isolate_libs): ../script/isolate_for_tests + @cd .. && $(RUBY) script/isolate_for_tests +-include $(isolate_libs) +MYLIBS := $(RUBYLIB):$(ISOLATE_LIBS) + T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) all:: $(T) @@ -58,7 +64,7 @@ $(test_prefix)/.stamp: $(T): export RUBY := $(RUBY) $(T): export RAKE := $(RAKE) $(T): export PATH := $(test_prefix)/bin:$(PATH) -$(T): export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB) +$(T): export RUBYLIB := $(test_prefix)/lib:$(MYLIBS) $(T): dep $(test_prefix)/.stamp trash/.gitignore $(TRACER) $(SHELL) $(SH_TEST_OPTS) $@ $(TEST_OPTS) diff --git a/t/preread_input.ru b/t/preread_input.ru new file mode 100644 index 0000000..79685c4 --- /dev/null +++ b/t/preread_input.ru @@ -0,0 +1,17 @@ +#\-E none +require 'digest/sha1' +require 'unicorn/preread_input' +use Rack::ContentLength +use Rack::ContentType, "text/plain" +use Unicorn::PrereadInput +nr = 0 +run lambda { |env| + $stderr.write "app dispatch: #{nr += 1}\n" + input = env["rack.input"] + dig = Digest::SHA1.new + while buf = input.read(16384) + dig.update(buf) + end + + [ 200, {}, [ "#{dig.hexdigest}\n" ] ] +} diff --git a/t/rails3-app/Gemfile b/t/rails3-app/Gemfile index 491e910..d996f34 100644 --- a/t/rails3-app/Gemfile +++ b/t/rails3-app/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -# gem 'rails', '3.0.0.beta3' +# gem 'rails', '3.0.0' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' diff --git a/t/t0003-working_directory.sh b/t/t0003-working_directory.sh index 53345ae..79988d8 100755 --- a/t/t0003-working_directory.sh +++ b/t/t0003-working_directory.sh @@ -1,9 +1,4 @@ #!/bin/sh -if test -n "$RBX_SKIP" -then - echo "$0 is broken under Rubinius for now" - exit 0 -fi . ./test-lib.sh t_plan 4 "config.ru inside alt working_directory" diff --git a/t/t0010-reap-logging.sh b/t/t0010-reap-logging.sh new file mode 100755 index 0000000..93d8c60 --- /dev/null +++ b/t/t0010-reap-logging.sh @@ -0,0 +1,55 @@ +#!/bin/sh +. ./test-lib.sh +t_plan 9 "reap worker logging messages" + +t_begin "setup and start" && { + unicorn_setup + cat >> $unicorn_config <<EOF +after_fork { |s,w| File.open('$fifo','w') { |f| f.write '.' } } +EOF + unicorn -c $unicorn_config pid.ru & + test '.' = $(cat $fifo) + unicorn_wait_start +} + +t_begin "kill 1st worker=0" && { + pid_1=$(curl http://$listen/) + kill -9 $pid_1 +} + +t_begin "wait for 2nd worker to start" && { + test '.' = $(cat $fifo) +} + +t_begin "ensure log of 1st reap is an ERROR" && { + dbgcat r_err + grep 'ERROR.*reaped.*worker=0' $r_err | grep $pid_1 + dbgcat r_err + > $r_err +} + +t_begin "kill 2nd worker gracefully" && { + pid_2=$(curl http://$listen/) + kill -QUIT $pid_2 +} + +t_begin "wait for 3rd worker=0 to start " && { + test '.' = $(cat $fifo) +} + +t_begin "ensure log of 2nd reap is a INFO" && { + grep 'INFO.*reaped.*worker=0' $r_err | grep $pid_2 + > $r_err +} + +t_begin "killing succeeds" && { + kill $unicorn_pid + wait + kill -0 $unicorn_pid && false +} + +t_begin "check stderr" && { + check_stderr +} + +t_done diff --git a/t/t0011-active-unix-socket.sh b/t/t0011-active-unix-socket.sh new file mode 100644 index 0000000..6f9ac53 --- /dev/null +++ b/t/t0011-active-unix-socket.sh @@ -0,0 +1,79 @@ +#!/bin/sh +. ./test-lib.sh +t_plan 11 "existing UNIX domain socket check" + +read_pid_unix () { + x=$(printf 'GET / HTTP/1.0\r\n\r\n' | \ + socat - UNIX:$unix_socket | \ + tail -1) + test -n "$x" + y="$(expr "$x" : '\([0-9]\+\)')" + test x"$x" = x"$y" + test -n "$y" + echo "$y" +} + +t_begin "setup and start" && { + rtmpfiles unix_socket unix_config + rm -f $unix_socket + unicorn_setup + grep -v ^listen < $unicorn_config > $unix_config + echo "listen '$unix_socket'" >> $unix_config + unicorn -D -c $unix_config pid.ru + unicorn_wait_start + orig_master_pid=$unicorn_pid +} + +t_begin "get pid of worker" && { + worker_pid=$(read_pid_unix) + t_info "worker_pid=$worker_pid" +} + +t_begin "fails to start with existing pid file" && { + rm -f $ok + unicorn -D -c $unix_config pid.ru || echo ok > $ok + test x"$(cat $ok)" = xok +} + +t_begin "worker pid unchanged" && { + test x"$(read_pid_unix)" = x$worker_pid + > $r_err +} + +t_begin "fails to start with listening UNIX domain socket bound" && { + rm $ok $pid + unicorn -D -c $unix_config pid.ru || echo ok > $ok + test x"$(cat $ok)" = xok + > $r_err +} + +t_begin "worker pid unchanged (again)" && { + test x"$(read_pid_unix)" = x$worker_pid +} + +t_begin "nuking the existing Unicorn succeeds" && { + kill -9 $unicorn_pid $worker_pid + while kill -0 $unicorn_pid + do + sleep 1 + done + check_stderr +} + +t_begin "succeeds in starting with leftover UNIX domain socket bound" && { + test -S $unix_socket + unicorn -D -c $unix_config pid.ru + unicorn_wait_start +} + +t_begin "worker pid changed" && { + test x"$(read_pid_unix)" != x$worker_pid +} + +t_begin "killing succeeds" && { + kill $unicorn_pid +} + +t_begin "no errors" && check_stderr + +t_done diff --git a/t/t0303-rails3-alt-working_directory_config.ru.sh b/t/t0303-rails3-alt-working_directory_config.ru.sh index 444f05a..1433f94 100755 --- a/t/t0303-rails3-alt-working_directory_config.ru.sh +++ b/t/t0303-rails3-alt-working_directory_config.ru.sh @@ -1,9 +1,4 @@ #!/bin/sh -if test -n "$RBX_SKIP" -then - echo "$0 is broken under Rubinius for now" - exit 0 -fi . ./test-rails3.sh t_plan 5 "Rails 3 (beta) inside alt working_directory (w/ config.ru)" diff --git a/t/t9000-preread-input.sh b/t/t9000-preread-input.sh new file mode 100755 index 0000000..b9da05e --- /dev/null +++ b/t/t9000-preread-input.sh @@ -0,0 +1,48 @@ +#!/bin/sh +. ./test-lib.sh +t_plan 9 "PrereadInput middleware tests" + +t_begin "setup and start" && { + random_blob_sha1=$(rsha1 < random_blob) + unicorn_setup + unicorn -D -c $unicorn_config preread_input.ru + unicorn_wait_start +} + +t_begin "single identity request" && { + curl -sSf -T random_blob http://$listen/ > $tmp +} + +t_begin "sha1 matches" && { + test x"$(cat $tmp)" = x"$random_blob_sha1" +} + +t_begin "single chunked request" && { + curl -sSf -T- < random_blob http://$listen/ > $tmp +} + +t_begin "sha1 matches" && { + test x"$(cat $tmp)" = x"$random_blob_sha1" +} + +t_begin "app only dispatched twice" && { + test 2 -eq "$(grep 'app dispatch:' < $r_err | wc -l )" +} + +t_begin "aborted chunked request" && { + rm -f $tmp + curl -sSf -T- < $fifo http://$listen/ > $tmp & + curl_pid=$! + kill -9 $curl_pid + wait +} + +t_begin "app only dispatched twice" && { + test 2 -eq "$(grep 'app dispatch:' < $r_err | wc -l )" +} + +t_begin "killing succeeds" && { + kill -QUIT $unicorn_pid +} + +t_done diff --git a/t/test-rails3.sh b/t/test-rails3.sh index beeccf5..907ef0d 100644 --- a/t/test-rails3.sh +++ b/t/test-rails3.sh @@ -1,5 +1,5 @@ . ./test-lib.sh -RAILS_VERSION=${RAILS_VERSION-3.0.0.beta4} +RAILS_VERSION=${RAILS_VERSION-3.0.0} case $RUBY_VERSION in 1.8.7|1.9.2) ;; *) @@ -13,7 +13,7 @@ rails_gems=../tmp/isolate/rails-$RAILS_VERSION/gems rails_bin="$rails_gems/rails-$RAILS_VERSION/bin/rails" if ! test -d "$arch_gems" || ! test -d "$rails_gems" || ! test -x "$rails_bin" then - ( cd ../ && $RAKE isolate ) + ( cd ../ && ./script/isolate_for_tests ) fi for i in $arch_gems/*-* $rails_gems/*-* |