Rainbows! 0.96.0 - range support
[rainbows.git] / t / t0003-reopen-logs.sh
blob910a0a5db15afd102af0d5dd7929c9ed3921d211
1 #!/bin/sh
2 # don't set nr_client for Rev, only _one_ app running at once :x
3 nr_client=${nr_client-2}
4 . ./test-lib.sh
6 t_plan 19 "reopen rotated logs"
8 t_begin "setup and startup" && {
9 rtmpfiles curl_out curl_err r_rot
10 rainbows_setup $model
11 rainbows -D sleep.ru -c $unicorn_config
12 rainbows_wait_start
15 t_begin "ensure server is responsive" && {
16 curl -sSf http://$listen/ >/dev/null
19 t_begin "start $nr_client concurrent requests" && {
20 start=$(date +%s)
21 for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
23 ( curl -sSf http://$listen/2 >> $curl_out 2>> $curl_err ) &
24 done
27 t_begin "ensure stderr log is clean" && check_stderr
29 t_begin "external log rotation" && {
30 rm -f $r_rot
31 mv $r_err $r_rot
34 t_begin "send reopen log signal (USR1)" && {
35 kill -USR1 $rainbows_pid
38 t_begin "wait for rotated log to reappear" && {
39 nr=60
40 while ! test -f $r_err && test $nr -ge 0
42 sleep 1
43 nr=$(( $nr - 1 ))
44 done
47 t_begin "wait for worker to reopen logs" && {
48 nr=60
49 re="worker=.* done reopening logs"
50 while ! grep "$re" < $r_err >/dev/null && test $nr -ge 0
52 sleep 1
53 nr=$(( $nr - 1 ))
54 done
57 dbgcat r_rot
58 dbgcat r_err
60 t_begin "wait curl requests to finish" && {
61 wait
62 t_info elapsed=$(( $(date +%s) - $start ))
65 t_begin "ensure no errors from curl" && {
66 test ! -s $curl_err
69 t_begin "curl got $nr_client responses" && {
70 test "$(wc -l < $curl_out)" -eq $nr_client
73 t_begin "all responses were identical" && {
74 nr=$(sort < $curl_out | uniq | wc -l)
75 test "$nr" -eq 1
78 t_begin 'response was "Hello"' && {
79 test x$(sort < $curl_out | uniq) = xHello
82 t_begin "current server stderr is clean" && check_stderr
84 t_begin "rotated stderr is clean" && {
85 check_stderr $r_rot
88 t_begin "server is now writing logs to new stderr" && {
89 before_rot=$(wc -c < $r_rot)
90 before_err=$(wc -c < $r_err)
91 curl -sSfv http://$listen/
92 after_rot=$(wc -c < $r_rot)
93 after_err=$(wc -c < $r_err)
94 test $after_rot -eq $before_rot
95 test $after_err -gt $before_err
98 t_begin "stop server" && {
99 kill $rainbows_pid
102 dbgcat r_err
104 t_begin "current server stderr is clean" && check_stderr
105 t_begin "rotated stderr is clean" && check_stderr $r_rot
107 t_done