3 t_plan
13 "backout of USR2 upgrade"
6 test xSTART
= x
"$(cat $fifo)"
7 unicorn_pid
=$
(cat $pid)
10 t_begin
"setup and start" && {
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
20 File.open("$fifo", "wb") { |fp| fp.syswrite "START" }
24 unicorn
-D -c $unicorn_config pid.ru
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" && {
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" && {
50 test $orig_master_pid -eq $
(cat $pid.oldbin
)
53 t_begin
"ensure old worker is no longer running" && {
55 while kill -0 $orig_worker_pid 2>/dev
/null
58 test $i -lt 600 || die
"timed out"
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
72 t_begin
"gracefully kill new master and ensure it dies" && {
73 kill -QUIT $new_master_pid
75 while kill -0 $new_worker_pid 2>/dev
/null
78 test $i -lt 600 || die
"timed out"
83 t_begin
"ensure $pid.oldbin does not exist" && {
85 while test -s $pid.oldbin
88 test $i -lt 600 || die
"timed out"
94 test $i -lt 600 || die
"timed out"
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