about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--t/sha1.ru17
-rwxr-xr-xt/t3100-revactor-tee-input.sh49
2 files changed, 66 insertions, 0 deletions
diff --git a/t/sha1.ru b/t/sha1.ru
new file mode 100644
index 0000000..ec81fa4
--- /dev/null
+++ b/t/sha1.ru
@@ -0,0 +1,17 @@
+# SHA1 checksum generator
+bs = ENV['bs'] ? ENV['bs'].to_i : 4096
+require 'digest/sha1'
+use Rack::ContentLength
+app = lambda do |env|
+  /\A100-continue\z/i =~ env['HTTP_EXPECT'] and
+    return [ 100, {}, [] ]
+  digest = Digest::SHA1.new
+  input = env['rack.input']
+  buf = input.read(bs)
+  begin
+    digest.update(buf)
+  end while input.read(bs, buf)
+
+  [ 200, {'Content-Type' => 'text/plain'}, [ digest.hexdigest << "\n" ] ]
+end
+run app
diff --git a/t/t3100-revactor-tee-input.sh b/t/t3100-revactor-tee-input.sh
new file mode 100755
index 0000000..337000a
--- /dev/null
+++ b/t/t3100-revactor-tee-input.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+nr_client=${nr_client-25}
+nr_actor=${nr_actor-50}
+
+. ./test-lib.sh
+require_revactor
+
+eval $(unused_listen)
+unicorn_config=$(mktemp -t rainbows.$$.unicorn.rb.XXXXXXXX)
+curl_out=$(mktemp -t rainbows.$$.curl.out.XXXXXXXX)
+curl_err=$(mktemp -t rainbows.$$.curl.err.XXXXXXXX)
+r_err=$(mktemp -t rainbows.$$.r.err.XXXXXXXX)
+r_out=$(mktemp -t rainbows.$$.r.out.XXXXXXXX)
+pid=$(mktemp -t rainbows.$$.pid.XXXXXXXX)
+blob=$(mktemp -t rainbows.$$.blob.XXXXXXXX)
+TEST_RM_LIST="$TEST_RM_LIST $unicorn_config $lock_path $r_err $r_out"
+TEST_RM_LIST="$TEST_RM_LIST $curl_out $curl_err $blob"
+
+cat > $unicorn_config <<EOF
+listen "$listen"
+pid "$pid"
+stderr_path "$r_err"
+stdout_path "$r_out"
+Rainbows! do
+  use :Revactor
+  worker_connections $nr_actor
+end
+EOF
+
+echo pid=$pid
+rainbows -D sha1.ru -c $unicorn_config
+wait_for_pid $pid
+
+dd if=/dev/urandom bs=1M count=10 of=$blob 2>/dev/null
+
+start=$(date +%s)
+for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
+do
+        ( curl -sSf -T- < $blob http://$listen/$i >> $curl_out 2>> $curl_err ) &
+done
+wait
+echo elapsed=$(( $(date +%s) - $start ))
+
+kill $(cat $pid)
+test $nr_client -eq $(wc -l < $curl_out)
+test 1 -eq $(sort < $curl_out | uniq | wc -l)
+blob_sha1=$( expr "$(sha1sum < $blob)" : '\([a-f0-9]\+\)')
+echo blob_sha1=$blob_sha1
+test x"$blob_sha1" = x"$(sort < $curl_out | uniq)"