event_machine: avoid redundant open() for static files
[rainbows.git] / t / t0500-cramp-streaming.sh
blob0c18875b0e40d3b6e05a1439d7bd3d648f9f2dce
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
10 require_check cramp Cramp::VERSION
12 t_plan 7 "streaming test for Cramp"
14 CONFIG_RU=cramp/streaming.ru
16 t_begin "setup and start" && {
17 rainbows_setup
18 rtmpfiles a b c curl_err expect
20 # requiring Rubygems for this test only since Cramp depends on
21 # pre versions of several gems
22 # Like the rest of the EM/async stuff, it's not Rack::Lint compatible
23 rainbows -E deployment -D $CONFIG_RU -c $unicorn_config
24 rainbows_wait_start
27 # this will spew any unexpected input to stdout and be silent on success
28 check () {
30 t0=$(date +%s)
31 i=0
32 while read hello world
34 t1=$(date +%s)
35 diff=$(($t1 - $t0))
36 t_info "i=$i diff=$diff hello=$hello world=$world"
37 test $diff -ge 1 || echo "$i: diff: $diff < 1 second"
38 t0=$t1
39 test xHello = x"$hello" || echo "$i: Hello != $hello"
40 test xWorld = x"$world" || echo "$i: World != $world"
41 i=$(($i + 1))
42 test $i -le 3 || echo "$i: $i > 3"
43 done
47 t_begin "send async requests off in parallel" && {
48 t0=$(date +%s)
49 curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$a 2>&1 &
50 curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$b 2>&1 &
51 curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$c 2>&1 &
54 t_begin "wait for curl terminations" && {
55 wait
56 t1=$(date +%s)
57 elapsed=$(( $t1 - $t0 ))
58 t_info "elapsed=$elapsed (should be 4-5s)"
61 t_begin "termination signal sent" && {
62 kill $rainbows_pid
65 t_begin "no errors from curl" && {
66 test ! -s $curl_err
69 t_begin "no errors in stderr" && check_stderr
71 t_begin "silence is golden" && {
72 test ! -s $a
73 test ! -s $b
74 test ! -s $c
77 t_done