unicorn 1.1.5
[unicorn.git] / t / t0012-reload-empty-config.sh
blobc18c030362cf63edfb9547645f828902fd1a2fd0
1 #!/bin/sh
2 . ./test-lib.sh
3 t_plan 9 "reloading unset config resets defaults"
5 t_begin "setup and start" && {
6 unicorn_setup
7 rtmpfiles unicorn_config_orig before_reload after_reload
8 cat $unicorn_config > $unicorn_config_orig
9 cat >> $unicorn_config <<EOF
10 logger Logger.new(STDOUT)
11 preload_app true
12 timeout 0x7fffffff
13 worker_processes 2
14 after_fork { |s,w| }
15 \$dump_cfg = lambda { |fp,srv|
16 defaults = Unicorn::Configurator::DEFAULTS
17 defaults.keys.map { |x| x.to_s }.sort.each do |key|
18 next if key =~ %r{\Astd(?:err|out)_path\z}
19 key = key.to_sym
20 def_value = defaults[key]
21 srv_value = srv.__send__(key)
22 fp << "#{key}|#{srv_value}|#{def_value}\\n"
23 end
25 before_fork { |s,w|
26 File.open("$before_reload", "a") { |fp| \$dump_cfg.call(fp, s) }
28 before_exec { |s| }
29 EOF
30 unicorn -D -c $unicorn_config env.ru
31 unicorn_wait_start
34 t_begin "ensure worker is started" && {
35 curl -sSf http://$listen/ > $tmp
38 t_begin "replace config file with original(-ish)" && {
39 grep -v ^pid < $unicorn_config_orig > $unicorn_config
40 cat >> $unicorn_config <<EOF
41 before_fork { |s,w|
42 File.open("$after_reload", "a") { |fp| \$dump_cfg.call(fp, s) }
44 EOF
47 t_begin "reload signal succeeds" && {
48 kill -HUP $unicorn_pid
49 while ! egrep '(done|error) reloading' $r_err >/dev/null
51 sleep 1
52 done
54 grep 'done reloading' $r_err >/dev/null
57 t_begin "ensure worker is started" && {
58 curl -sSf http://$listen/ > $tmp
61 t_begin "pid file no longer exists" && {
62 if test -f $pid
63 then
64 die "pid=$pid should not exist"
68 t_begin "killing succeeds" && {
69 kill $unicorn_pid
72 t_begin "check stderr" && {
73 check_stderr
76 t_begin "ensure reloading restored settings" && {
77 awk < $after_reload -F'|' '
78 $1 != "before_fork" && $2 != $3 { print $0; exit(1) }
82 t_done