diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-11-28 11:43:45 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-11-28 12:19:21 -0800 |
commit | f824f4e13a13daf56439e16ecb3a62469a8c9bf0 (patch) | |
tree | 162c80491bdf7ad7d258479af092c23a5557c2be /t | |
parent | 2489368a624cff50a330238cf3c3f16eb0bd743c (diff) | |
download | rainbows-f824f4e13a13daf56439e16ecb3a62469a8c9bf0.tar.gz |
Some people fork processes, so it avoid hanging a connection open because of that...
Diffstat (limited to 't')
-rw-r--r-- | t/fork-sleep.ru | 10 | ||||
-rwxr-xr-x | t/t0011-close-on-exec-set.sh | 54 |
2 files changed, 64 insertions, 0 deletions
diff --git a/t/fork-sleep.ru b/t/fork-sleep.ru new file mode 100644 index 0000000..747a06d --- /dev/null +++ b/t/fork-sleep.ru @@ -0,0 +1,10 @@ +#\-E none +# we do not want Rack::Lint or anything to protect us +use Rack::ContentLength +use Rack::ContentType, "text/plain" +trap(:CHLD) { $stderr.puts Process.waitpid2(-1).inspect } +map "/" do + time = ENV["nr"] || '15' + pid = fork { exec('sleep', time) } + run lambda { |env| [ 200, {}, [ "#{pid}\n" ] ] } +end diff --git a/t/t0011-close-on-exec-set.sh b/t/t0011-close-on-exec-set.sh new file mode 100755 index 0000000..0429851 --- /dev/null +++ b/t/t0011-close-on-exec-set.sh @@ -0,0 +1,54 @@ +#!/bin/sh +nr=${nr-"5"} +. ./test-lib.sh + +t_plan 7 "ensure close-on-exec flag is set for $model" + +t_begin "setup and start" && { + rainbows_setup $model 1 1 + nr=$nr rainbows -D fork-sleep.ru -c $unicorn_config + rainbows_wait_start +} + +t_begin "send keepalive req expect it to timeout in ~1s" && { + req='GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' + t0=$(date +%s) + ( + cat $fifo > $tmp & + printf "$req" + wait + date +%s > $ok + ) | socat - TCP:$listen > $fifo + now="$(cat $ok)" + elapsed=$(( $now - $t0 )) + t_info "elapsed=$elapsed (expecting >=1s)" + test $elapsed -ge 1 +} + +t_begin 'sleep process is still running' && { + sleep_pid="$(tail -1 $tmp)" + kill -0 $sleep_pid +} + +t_begin 'keepalive not unreasonably long' && { + test $elapsed -lt $nr +} + +t_begin "killing succeeds" && { + kill $rainbows_pid +} + +t_begin "check stderr" && { + t_info "about to start waiting $nr seconds..." + sleep $nr + check_stderr +} + +t_begin 'sleep process is NOT running' && { + if kill -0 $sleep_pid + then + die "sleep process should've died" + fi +} + +t_done |