Rainbows! 5.2.1
[rainbows.git] / t / t0700-app-deferred.sh
blob188fdde7adbacbbebd83e0ad0592f101c4b65524
1 #!/bin/sh
2 . ./test-lib.sh
3 case $model in
4 EventMachine) ;;
5 *)
6 t_info "skipping $T since it's not compatible with $model"
7 exit 0
8 ;;
9 esac
11 t_plan 5 "basic test for app.deferred? usage"
13 CONFIG_RU=app_deferred.ru
15 t_begin "setup and start" && {
16 rainbows_setup
17 rtmpfiles deferred_err deferred_out sync_err sync_out
18 fifo=$fifo rainbows -D -c $unicorn_config $CONFIG_RU
19 rainbows_wait_start
22 t_begin "synchronous requests run in the same thread" && {
23 curl --no-buffer -sSf http://$listen/ >> $sync_out 2>> $sync_err &
24 curl --no-buffer -sSf http://$listen/ >> $sync_out 2>> $sync_err &
25 curl --no-buffer -sSf http://$listen/ >> $sync_out 2>> $sync_err &
26 wait
27 test ! -s $sync_err
28 test 3 -eq "$(count_lines < $sync_out)"
29 test 1 -eq "$(uniq < $sync_out | count_lines)"
32 t_begin "deferred requests run in a different thread" && {
33 curl -sSf http://$listen/deferred >> $deferred_out 2>> $deferred_err
34 test ! -s $deferred_err
35 sync_thread="$(uniq < $sync_out)"
36 test x"$(uniq < $deferred_out)" != x"$sync_thread"
39 t_begin "deferred requests run after graceful shutdown" && {
40 # XXX sleeping 5s ought to be enough for SIGQUIT to arrive,
41 # hard to tell with overloaded systems...
42 s=5
43 curl -sSf --no-buffer http://$listen/deferred$s \
44 >$deferred_out 2>$deferred_err &
45 curl_pid=$!
46 msg="$(cat $fifo)"
47 kill -QUIT $rainbows_pid
48 test x"$msg" = x"sleeping ${s}s"
49 wait $curl_pid # for curl to finish
50 test $? -eq 0
51 test ! -s $deferred_err
52 test x"$(cat $deferred_out)" = 'xdeferred sleep'
55 t_begin "no errors in stderr" && check_stderr
57 t_done