doc: various updates and disclaimers
[unicorn.git] / t / t0012-reload-empty-config.sh
blob47d18ce886511d48de6c66a9ee654374bb7b3f97
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.respond_to?(key) ? srv.__send__(key)
22 : srv.instance_variable_get("@#{key}")
23 fp << "#{key}|#{srv_value}|#{def_value}\\n"
24 end
26 before_fork { |s,w|
27 File.open("$before_reload", "a") { |fp| \$dump_cfg.call(fp, s) }
29 before_exec { |s| }
30 EOF
31 unicorn -D -c $unicorn_config env.ru
32 unicorn_wait_start
35 t_begin "ensure worker is started" && {
36 curl -sSf http://$listen/ > $tmp
39 t_begin "replace config file with original(-ish)" && {
40 grep -v ^pid < $unicorn_config_orig > $unicorn_config
41 cat >> $unicorn_config <<EOF
42 before_fork { |s,w|
43 File.open("$after_reload", "a") { |fp| \$dump_cfg.call(fp, s) }
45 EOF
48 t_begin "reload signal succeeds" && {
49 kill -HUP $unicorn_pid
50 while ! egrep '(done|error) reloading' $r_err >/dev/null
52 sleep 1
53 done
54 while ! grep reaped < $r_err >/dev/null
56 sleep 1
57 done
58 grep 'done reloading' $r_err >/dev/null
61 t_begin "ensure worker is started" && {
62 curl -sSf http://$listen/ > $tmp
65 t_begin "pid file no longer exists" && {
66 if test -f $pid
67 then
68 die "pid=$pid should not exist"
72 t_begin "killing succeeds" && {
73 kill $unicorn_pid
76 t_begin "check stderr" && {
77 check_stderr
80 t_begin "ensure reloading restored settings" && {
81 awk < $after_reload -F'|' '
82 $1 != "before_fork" && $2 != $3 { print $0; exit(1) }
86 t_done