tests: predictable and simpler tempfile management
[rainbows.git] / t / lib-reopen-logs.sh
blob813f20420a37a90d2c85c73414b42fb62800c458
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 eval $(unused_listen)
7 rtmpfiles unicorn_config curl_out curl_err pid r_err r_out r_rot
10 cat > $unicorn_config <<EOF
11 listen "$listen"
12 pid "$pid"
13 stderr_path "$r_err"
14 stdout_path "$r_out"
15 Rainbows! { use :$model }
16 EOF
18 rainbows -D sleep.ru -c $unicorn_config
19 wait_for_pid $pid
21 start=$(date +%s)
22 for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
24 ( curl -sSf http://$listen/2 >> $curl_out 2>> $curl_err ) &
25 done
26 check_stderr
28 rm -f $r_rot
29 mv $r_err $r_rot
31 kill -USR1 $(cat $pid)
32 wait_for_pid $r_err
34 dbgcat r_rot
35 dbgcat r_err
37 wait
38 echo elapsed=$(( $(date +%s) - $start ))
39 test ! -s $curl_err
40 test x"$(wc -l < $curl_out)" = x$nr_client
41 nr=$(sort < $curl_out | uniq | wc -l)
43 test "$nr" -eq 1
44 test x$(sort < $curl_out | uniq) = xHello
45 check_stderr
46 check_stderr $r_rot
48 before_rot=$(wc -c < $r_rot)
49 before_err=$(wc -c < $r_err)
50 curl -sSfv http://$listen/
51 after_rot=$(wc -c < $r_rot)
52 after_err=$(wc -c < $r_err)
54 test $after_rot -eq $before_rot && echo "before_rot -eq after_rot"
55 test $after_err -gt $before_err && echo "before_err -gt after_err"
57 kill $(cat $pid)
58 dbgcat r_err
59 check_stderr
60 check_stderr $r_rot