diff options
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 |