examples: add run_once to before_fork hook example
[unicorn.git] / t / t0009-winch_ttin.sh
blob6e56e30c43c5c67bcafd4ad77b03b7a36d64f523
1 #!/bin/sh
2 . ./test-lib.sh
3 t_plan 8 "SIGTTIN succeeds after SIGWINCH"
5 t_begin "setup and start" && {
6 unicorn_setup
7 cat >> $unicorn_config <<EOF
8 after_fork do |server, worker|
9 # test script will block while reading from $fifo,
10 File.open("$fifo", "wb") { |fp| fp.syswrite worker.nr.to_s }
11 end
12 EOF
13 unicorn -D -c $unicorn_config pid.ru
14 unicorn_wait_start
15 test 0 -eq $(cat $fifo) || die "worker.nr != 0"
18 t_begin "read worker pid" && {
19 orig_worker_pid=$(curl -sSf http://$listen/)
20 test -n "$orig_worker_pid" && kill -0 $orig_worker_pid
23 t_begin "stop all workers" && {
24 kill -WINCH $unicorn_pid
27 # we have to do this next step before delivering TTIN
28 # signals aren't guaranteed to delivered in order
29 t_begin "wait for worker to die" && {
30 i=0
31 while kill -0 $orig_worker_pid 2>/dev/null
33 i=$(( $i + 1 ))
34 test $i -lt 600 || die "timed out"
35 sleep 1
36 done
39 t_begin "start one worker back up" && {
40 kill -TTIN $unicorn_pid
43 t_begin "wait for new worker to start" && {
44 test 0 -eq $(cat $fifo) || die "worker.nr != 0"
45 new_worker_pid=$(curl -sSf http://$listen/)
46 test -n "$new_worker_pid" && kill -0 $new_worker_pid
47 test $orig_worker_pid -ne $new_worker_pid || \
48 die "worker wasn't replaced"
51 t_begin "killing succeeds" && {
52 kill $unicorn_pid
55 t_begin "check stderr" && check_stderr
57 dbgcat r_err
59 t_done