about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-01-08 16:44:44 -0800
committerEric Wong <normalperson@yhbt.net>2010-01-08 17:01:27 -0800
commit0b6fe07c10278266e2f428a4355b7edfc13781cd (patch)
tree917e3510c0ea47fd27f858ada0076cc0864afd1f
parent23bf8da0774b21d8c55786b4b386faba4b53c97f (diff)
downloadrainbows-0b6fe07c10278266e2f428a4355b7edfc13781cd.tar.gz
Tested with cramp-0.7 and eventmachine 0.12.10
-rw-r--r--local.mk.sample11
-rw-r--r--t/cramp/README3
-rw-r--r--t/cramp/streaming.ru28
-rwxr-xr-xt/t0500-cramp-streaming.sh77
4 files changed, 119 insertions, 0 deletions
diff --git a/local.mk.sample b/local.mk.sample
index 8129807..e6b4daf 100644
--- a/local.mk.sample
+++ b/local.mk.sample
@@ -14,6 +14,17 @@ gems += eventmachine-0.12.10
 gems += async_sinatra-0.1.5 sinatra-0.9.4
 gems += espace-neverblock-0.1.6.1
 
+# Cramp isn't enabled by default since it depends on several prerelease gems
+ifdef CRAMP
+  gems += cramp-0.7
+  gems += activesupport-3.0.pre
+  gems += activemodel-3.0.pre
+  gems += arel-0.2.pre
+  gems += usher-0.6.2
+  gems += fuzzyhash-0.0.11
+  gems += mysqlplus-0.1.1
+endif
+
 # Avoid loading rubygems to speed up tests because gmake is
 # fork+exec heavy with Ruby.
 prefix = $(HOME)
diff --git a/t/cramp/README b/t/cramp/README
new file mode 100644
index 0000000..9fffe89
--- /dev/null
+++ b/t/cramp/README
@@ -0,0 +1,3 @@
+These examples in this directory are stolen from Cramp with only trivial
+changes.  All examples in this directory retain their original license
+(MIT) and copyrights.
diff --git a/t/cramp/streaming.ru b/t/cramp/streaming.ru
new file mode 100644
index 0000000..dc470b2
--- /dev/null
+++ b/t/cramp/streaming.ru
@@ -0,0 +1,28 @@
+# based on examples/streaming.rb in git://github.com/lifo/cramp
+# commit ca54f8a944ae582a0c858209daf3c74efea7d27c
+
+# Rack::Lint does not like async + EM stuff, so disable it:
+#\ -E deployment
+
+require 'cramp/controller'
+
+class StreamController < Cramp::Controller::Action
+  periodic_timer :send_data, :every => 1
+  periodic_timer :check_limit, :every => 2
+
+  def start
+    @limit = 0
+  end
+
+  def send_data
+    render ["Hello World", "\n"]
+  end
+
+  def check_limit
+    @limit += 1
+    finish if @limit > 1
+  end
+
+end
+
+run StreamController
diff --git a/t/t0500-cramp-streaming.sh b/t/t0500-cramp-streaming.sh
new file mode 100755
index 0000000..0c18875
--- /dev/null
+++ b/t/t0500-cramp-streaming.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+. ./test-lib.sh
+case $model in
+EventMachine) ;;
+*)
+        t_info "skipping $T since it's not compatible with $model"
+        exit 0
+        ;;
+esac
+require_check cramp Cramp::VERSION
+
+t_plan 7 "streaming test for Cramp"
+
+CONFIG_RU=cramp/streaming.ru
+
+t_begin "setup and start" && {
+        rainbows_setup
+        rtmpfiles a b c curl_err expect
+
+        # requiring Rubygems for this test only since Cramp depends on
+        # pre versions of several gems
+        # Like the rest of the EM/async stuff, it's not Rack::Lint compatible
+        rainbows -E deployment -D $CONFIG_RU -c $unicorn_config
+        rainbows_wait_start
+}
+
+# this will spew any unexpected input to stdout and be silent on success
+check () {
+        (
+                t0=$(date +%s)
+                i=0
+                while read hello world
+                do
+                        t1=$(date +%s)
+                        diff=$(($t1 - $t0))
+                        t_info "i=$i diff=$diff hello=$hello world=$world"
+                        test $diff -ge 1 || echo "$i: diff: $diff < 1 second"
+                        t0=$t1
+                        test xHello = x"$hello" || echo "$i: Hello != $hello"
+                        test xWorld = x"$world" || echo "$i: World != $world"
+                        i=$(($i + 1))
+                        test $i -le 3 || echo "$i: $i > 3"
+                done
+        )
+}
+
+t_begin "send async requests off in parallel" && {
+        t0=$(date +%s)
+        curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$a 2>&1 &
+        curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$b 2>&1 &
+        curl --no-buffer -sSf http://$listen/ 2>> $curl_err | check >$c 2>&1 &
+}
+
+t_begin "wait for curl terminations" && {
+        wait
+        t1=$(date +%s)
+        elapsed=$(( $t1 - $t0 ))
+        t_info "elapsed=$elapsed (should be 4-5s)"
+}
+
+t_begin "termination signal sent" && {
+        kill $rainbows_pid
+}
+
+t_begin "no errors from curl" && {
+        test ! -s $curl_err
+}
+
+t_begin "no errors in stderr" && check_stderr
+
+t_begin "silence is golden" && {
+        test ! -s $a
+        test ! -s $b
+        test ! -s $c
+}
+
+t_done