Rack::Chunked and ContentLength middlewares by default
[unicorn.git] / t / t0020-at_exit-handler.sh
blobfda14b59b9cecd1c8e3c9c076fbf553fe6b82085
1 #!/bin/sh
2 . ./test-lib.sh
4 t_plan 5 "at_exit/END handlers work as expected"
6 t_begin "setup and startup" && {
7 unicorn_setup
8 cat >> $unicorn_config <<EOF
9 at_exit { \$stdout.syswrite("#{Process.pid} BOTH\\n") }
10 END { \$stdout.syswrite("#{Process.pid} END BOTH\\n") }
11 after_fork do |_,_|
12 at_exit { \$stdout.syswrite("#{Process.pid} WORKER ONLY\\n") }
13 END { \$stdout.syswrite("#{Process.pid} END WORKER ONLY\\n") }
14 end
15 EOF
17 unicorn -D pid.ru -c $unicorn_config
18 unicorn_wait_start
21 t_begin "read worker PID" && {
22 worker_pid=$(curl -sSf http://$listen/)
23 t_info "worker_pid=$worker_pid"
26 t_begin "issue graceful shutdown (SIGQUIT) and wait for termination" && {
27 kill -QUIT $unicorn_pid
29 while kill -0 $unicorn_pid >/dev/null 2>&1
31 sleep 1
32 done
35 t_begin "check stderr" && check_stderr
37 dbgcat r_err
38 dbgcat r_out
40 t_begin "all at_exit handlers ran" && {
41 grep "$worker_pid BOTH" $r_out
42 grep "$unicorn_pid BOTH" $r_out
43 grep "$worker_pid END BOTH" $r_out
44 grep "$unicorn_pid END BOTH" $r_out
45 grep "$worker_pid WORKER ONLY" $r_out
46 grep "$worker_pid END WORKER ONLY" $r_out
49 t_done