diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-04-29 15:48:35 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-04-29 16:01:14 -0700 |
commit | faeb3223636c39ea8df4017dc9a9d39ac649b26d (patch) | |
tree | fce6b3ee71fc84e41ed3227ff2136b167b2d59b6 /t | |
parent | ce4995a4daf1e4da7034dc87fd218a283c405410 (diff) | |
download | unicorn-faeb3223636c39ea8df4017dc9a9d39ac649b26d.tar.gz |
This was broken since v3.3.1[1] since nginx relies on a closed socket (and not Content-Length/Transfer-Encoding) to detect a response completion. We have to close the client socket before invoking GC to ensure the client sees the response in a timely manner. [1] - commit b72a86f66c722d56a6d77ed1d2779ace6ad103ed
Diffstat (limited to 't')
-rw-r--r-- | t/oob_gc.ru | 21 | ||||
-rw-r--r-- | t/oob_gc_path.ru | 21 | ||||
-rwxr-xr-x | t/t9001-oob_gc.sh | 47 | ||||
-rw-r--r-- | t/t9002-oob_gc-path.sh | 75 |
4 files changed, 164 insertions, 0 deletions
diff --git a/t/oob_gc.ru b/t/oob_gc.ru new file mode 100644 index 0000000..c6035b6 --- /dev/null +++ b/t/oob_gc.ru @@ -0,0 +1,21 @@ +#\-E none +require 'unicorn/oob_gc' +use Rack::ContentLength +use Rack::ContentType, "text/plain" +use Unicorn::OobGC +$gc_started = false + +# Mock GC.start +def GC.start + ObjectSpace.each_object(BasicSocket) do |x| + next if Unicorn::HttpServer::LISTENERS.include?(x) + x.closed? or abort "not closed #{x}" + end + $gc_started = true +end +run lambda { |env| + if "/gc_reset" == env["PATH_INFO"] && "POST" == env["REQUEST_METHOD"] + $gc_started = false + end + [ 200, {}, [ "#$gc_started\n" ] ] +} diff --git a/t/oob_gc_path.ru b/t/oob_gc_path.ru new file mode 100644 index 0000000..e936a85 --- /dev/null +++ b/t/oob_gc_path.ru @@ -0,0 +1,21 @@ +#\-E none +require 'unicorn/oob_gc' +use Rack::ContentLength +use Rack::ContentType, "text/plain" +use Unicorn::OobGC, 5, /BAD/ +$gc_started = false + +# Mock GC.start +def GC.start + ObjectSpace.each_object(BasicSocket) do |x| + next if Unicorn::HttpServer::LISTENERS.include?(x) + x.closed? or abort "not closed #{x}" + end + $gc_started = true +end +run lambda { |env| + if "/gc_reset" == env["PATH_INFO"] && "POST" == env["REQUEST_METHOD"] + $gc_started = false + end + [ 200, {}, [ "#$gc_started\n" ] ] +} diff --git a/t/t9001-oob_gc.sh b/t/t9001-oob_gc.sh new file mode 100755 index 0000000..dcd8100 --- /dev/null +++ b/t/t9001-oob_gc.sh @@ -0,0 +1,47 @@ +#!/bin/sh +. ./test-lib.sh +t_plan 9 "OobGC test" + +t_begin "setup and start" && { + unicorn_setup + unicorn -D -c $unicorn_config oob_gc.ru + unicorn_wait_start +} + +t_begin "test default interval (4 requests)" && { + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "GC starting-request returns immediately" && { + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "GC is started after 5 requests" && { + test xtrue = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "reset GC" && { + test xfalse = x$(curl -vsSf -X POST http://$listen/gc_reset 2>> $tmp) +} + +t_begin "test default interval again (3 requests)" && { + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "GC is started after 5 requests" && { + test xtrue = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "killing succeeds" && { + kill -QUIT $unicorn_pid +} + +t_begin "check_stderr" && check_stderr +dbgcat r_err + +t_done diff --git a/t/t9002-oob_gc-path.sh b/t/t9002-oob_gc-path.sh new file mode 100644 index 0000000..d4e795b --- /dev/null +++ b/t/t9002-oob_gc-path.sh @@ -0,0 +1,75 @@ +#!/bin/sh +. ./test-lib.sh +t_plan 12 "OobGC test with limited path" + +t_begin "setup and start" && { + unicorn_setup + unicorn -D -c $unicorn_config oob_gc_path.ru + unicorn_wait_start +} + +t_begin "test default is noop" && { + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "4 bad requests to bump counter" && { + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) +} + +t_begin "GC-starting request returns immediately" && { + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) +} + +t_begin "GC was started after 5 requests" && { + test xtrue = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "reset GC" && { + test xfalse = x$(curl -vsSf -X POST http://$listen/gc_reset 2>> $tmp) +} + +t_begin "test default is noop" && { + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "4 bad requests to bump counter" && { + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) +} + +t_begin "GC-starting request returns immediately" && { + test xfalse = x$(curl -vsSf http://$listen/BAD 2>> $tmp) +} + +t_begin "GC was started after 5 requests" && { + test xtrue = x$(curl -vsSf http://$listen/ 2>> $tmp) +} + +t_begin "killing succeeds" && { + kill -QUIT $unicorn_pid +} + +t_begin "check_stderr" && check_stderr + +t_done |