tests: replace non-portable "date +%s" with ruby equivalent
[rainbows.git] / t / t0500-cramp-streaming.sh
blobfe798d3b96223ae775338a66d73e909a1316fb66
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 RUBYLIB=$($RUBY test_isolate_cramp.rb):$RUBYLIB
11 export RUBYLIB
12 require_check cramp Cramp::VERSION
14 t_plan 7 "streaming test for Cramp"
16 CONFIG_RU=cramp/streaming.ru
18 t_begin "setup and start" && {
19 rainbows_setup
20 rtmpfiles a b c curl_err expect
22 # requiring Rubygems for this test only since Cramp depends on
23 # pre versions of several gems
24 # Like the rest of the EM/async stuff, it's not Rack::Lint compatible
25 rainbows -E deployment -D $CONFIG_RU -c $unicorn_config
26 rainbows_wait_start
29 # this will spew any unexpected input to stdout and be silent on success
30 check () {
32 i=0
33 while read hello world
35 t1=$(unix_time)
36 diff=$(($t1 - $t0))
37 t_info "i=$i diff=$diff hello=$hello world=$world"
38 test $diff -ge 1 || echo "$i: diff: $diff < 1 second"
39 t0=$t1
40 test xHello = x"$hello" || echo "$i: Hello != $hello"
41 test xWorld = x"$world" || echo "$i: World != $world"
42 i=$(($i + 1))
43 test $i -le 3 || echo "$i: $i > 3"
44 done
48 t_begin "send async requests off in parallel" && {
49 t0=$(unix_time)
50 curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$a 2>&1 &
51 curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$b 2>&1 &
52 curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$c 2>&1 &
55 t_begin "wait for curl terminations" && {
56 wait
57 t1=$(unix_time)
58 elapsed=$(( $t1 - $t0 ))
59 t_info "elapsed=$elapsed (should be 4-5s)"
62 t_begin "termination signal sent" && {
63 kill $rainbows_pid
66 t_begin "no errors from curl" && {
67 test ! -s $curl_err
70 t_begin "no errors in stderr" && check_stderr
72 t_begin "silence is golden" && {
73 test ! -s $a
74 test ! -s $b
75 test ! -s $c
78 t_done