httpdate: favor gettimeofday(2) over time(2) for correctness
[unicorn.git] / t / t0008-back_out_of_upgrade.sh
blob96d40575b1cafcf03a2527d3604a35f67bf12e3a
1 #!/bin/sh
2 . ./test-lib.sh
3 t_plan 13 "backout of USR2 upgrade"
5 worker_wait_start () {
6 test xSTART = x"$(cat $fifo)"
7 unicorn_pid=$(cat $pid)
10 t_begin "setup and start" && {
11 unicorn_setup
12 rm -f $pid.oldbin
14 cat >> $unicorn_config <<EOF
15 after_fork do |server, worker|
16 # test script will block while reading from $fifo,
17 # so notify the script on the first worker we spawn
18 # by opening the FIFO
19 if worker.nr == 0
20 File.open("$fifo", "wb") { |fp| fp.syswrite "START" }
21 end
22 end
23 EOF
24 unicorn -D -c $unicorn_config pid.ru
25 worker_wait_start
26 orig_master_pid=$unicorn_pid
29 t_begin "read original worker pid" && {
30 orig_worker_pid=$(curl -sSf http://$listen/)
31 test -n "$orig_worker_pid" && kill -0 $orig_worker_pid
34 t_begin "upgrade to new master" && {
35 kill -USR2 $orig_master_pid
38 t_begin "kill old worker" && {
39 kill -WINCH $orig_master_pid
42 t_begin "wait for new worker to start" && {
43 worker_wait_start
44 test $unicorn_pid -ne $orig_master_pid
45 new_master_pid=$unicorn_pid
48 t_begin "old master pid is stashed in $pid.oldbin" && {
49 test -s "$pid.oldbin"
50 test $orig_master_pid -eq $(cat $pid.oldbin)
53 t_begin "ensure old worker is no longer running" && {
54 i=0
55 while kill -0 $orig_worker_pid 2>/dev/null
57 i=$(( $i + 1 ))
58 test $i -lt 600 || die "timed out"
59 sleep 1
60 done
63 t_begin "capture pid of new worker" && {
64 new_worker_pid=$(curl -sSf http://$listen/)
67 t_begin "reload old master process" && {
68 kill -HUP $orig_master_pid
69 worker_wait_start
72 t_begin "gracefully kill new master and ensure it dies" && {
73 kill -QUIT $new_master_pid
74 i=0
75 while kill -0 $new_worker_pid 2>/dev/null
77 i=$(( $i + 1 ))
78 test $i -lt 600 || die "timed out"
79 sleep 1
80 done
83 t_begin "ensure $pid.oldbin does not exist" && {
84 i=0
85 while test -s $pid.oldbin
87 i=$(( $i + 1 ))
88 test $i -lt 600 || die "timed out"
89 sleep 1
90 done
91 while ! test -s $pid
93 i=$(( $i + 1 ))
94 test $i -lt 600 || die "timed out"
95 sleep 1
96 done
99 t_begin "ensure $pid is correct" && {
100 cur_master_pid=$(cat $pid)
101 test $orig_master_pid -eq $cur_master_pid
104 t_begin "killing succeeds" && {
105 kill $orig_master_pid
108 dbgcat r_err
110 t_done