From a83f898b9faf193698185a89762d8eac08cc7736 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 6 Oct 2009 00:48:04 -0700 Subject: tests: generate random_blob once for all tests We don't need to repeatedly waste cycles and memory bandwidth to generate random throwaway data. --- t/.gitignore | 1 + t/GNUmakefile | 7 +++++++ t/t3100-revactor-tee-input.sh | 13 +++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 't') diff --git a/t/.gitignore b/t/.gitignore index 7cb5e32..d2d3d0e 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -2,3 +2,4 @@ /test-bin-* /*.code /*.log +/random_blob diff --git a/t/GNUmakefile b/t/GNUmakefile index 50b1867..76776da 100644 --- a/t/GNUmakefile +++ b/t/GNUmakefile @@ -56,6 +56,13 @@ test-bin-$(RUBY_VERSION)/rainbows: ../bin/rainbows cmp $@+ $@ 2>/dev/null || mv $@+ $@ $(RM) $@+ +req_random_blob := t3100-revactor-tee-input +random_blob: + dd if=/dev/urandom bs=1M count=10 of=$@+ + mv $@+ $@ + +$(addsuffix .sh,$(req_random_blob)): random_blob + $(T): export ruby := $(ruby) $(T): export PATH := $(CURDIR)/test-bin-$(RUBY_VERSION):$(PATH) $(T): test-bin-$(RUBY_VERSION)/rainbows diff --git a/t/t3100-revactor-tee-input.sh b/t/t3100-revactor-tee-input.sh index 2cbc73b..eb17a8b 100755 --- a/t/t3100-revactor-tee-input.sh +++ b/t/t3100-revactor-tee-input.sh @@ -4,6 +4,7 @@ nr_actor=${nr_actor-50} . ./test-lib.sh require_revactor +test -r random_blob || die "random_blob required, run with 'make $0'" eval $(unused_listen) unicorn_config=$(mktemp -t rainbows.$$.unicorn.rb.XXXXXXXX) @@ -12,9 +13,8 @@ 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 $pid" +TEST_RM_LIST="$TEST_RM_LIST $curl_out $curl_err $pid" cat > $unicorn_config </dev/null - start=$(date +%s) for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" > $curl_out 2>> $curl_err ) & + ( + curl -sSf -T- http://$listen/$i \ + < random_blob >> $curl_out 2>> $curl_err + ) & done wait echo elapsed=$(( $(date +%s) - $start )) @@ -44,6 +45,6 @@ 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]\+\)') +blob_sha1=$( expr "$(sha1sum < random_blob)" : '\([a-f0-9]\+\)') echo blob_sha1=$blob_sha1 test x"$blob_sha1" = x"$(sort < $curl_out | uniq)" -- cgit v1.2.3-24-ge0c7