about summary refs log tree commit homepage
path: root/t/t0011-close-on-exec-set.sh
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-28 11:43:45 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-28 12:19:21 -0800
commitf824f4e13a13daf56439e16ecb3a62469a8c9bf0 (patch)
tree162c80491bdf7ad7d258479af092c23a5557c2be /t/t0011-close-on-exec-set.sh
parent2489368a624cff50a330238cf3c3f16eb0bd743c (diff)
downloadrainbows-f824f4e13a13daf56439e16ecb3a62469a8c9bf0.tar.gz
Some people fork processes, so it avoid hanging a connection
open because of that...
Diffstat (limited to 't/t0011-close-on-exec-set.sh')
-rwxr-xr-xt/t0011-close-on-exec-set.sh54
1 files changed, 54 insertions, 0 deletions
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