From 39f625fff05d457b01f088017f463a86d3b6c626 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 16 May 2011 19:04:06 +0000 Subject: add "copy_stream" config directive This allows using IO::Splice.copy_stream from the "io_splice" RubyGem on recent Linux systems. This also allows users to disable copy_stream usage entirely and use traditional response_body.each calls which are compatible with all Rack servers (to workaround bugs in IO.copy_stream under 1.9.2-p180). --- t/t0026-splice-copy_stream-byte-range.sh | 40 +++++++++++++++++++ t/t0027-nil-copy_stream.sh | 68 ++++++++++++++++++++++++++++++++ t/test-lib.sh | 27 +++++++++++++ t/test_isolate.rb | 7 +++- 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 t/t0026-splice-copy_stream-byte-range.sh create mode 100644 t/t0027-nil-copy_stream.sh (limited to 't') diff --git a/t/t0026-splice-copy_stream-byte-range.sh b/t/t0026-splice-copy_stream-byte-range.sh new file mode 100644 index 0000000..70546b6 --- /dev/null +++ b/t/t0026-splice-copy_stream-byte-range.sh @@ -0,0 +1,40 @@ +#!/bin/sh +. ./test-lib.sh +test -r random_blob || die "random_blob required, run with 'make $0'" +case $RUBY_VERSION in +1.9.*) ;; +*) + t_info "skipping $T since it can't IO::Splice.copy_stream" + exit 0 + ;; +esac +check_splice + +case $model in +ThreadSpawn|WriterThreadSpawn|ThreadPool|WriterThreadPool|Base) ;; +XEpollThreadSpawn) ;; +*) + t_info "skipping $T since it doesn't use copy_stream" + exit 0 + ;; +esac + +t_plan 13 "IO::Splice.copy_stream byte range response for $model" + +t_begin "setup and startup" && { + rtmpfiles out err + rainbows_setup $model + cat >> $unicorn_config <> $unicorn_config <$ok) | rsha1) + test $sha1 = $random_blob_sha1 + test xok = x$(cat $ok) + done +} + +# this was a problem during development +t_begin "HTTP/1.0 test" && { + sha1=$( (curl -0 -sSfv http://$listen/random_blob && + echo ok >$ok) | rsha1) + test $sha1 = $random_blob_sha1 + test xok = x$(cat $ok) +} + +t_begin "HTTP/0.9 test" && { + ( + printf 'GET /random_blob\r\n' + rsha1 < $fifo > $tmp & + wait + echo ok > $ok + ) | socat - TCP:$listen > $fifo + test $(cat $tmp) = $random_blob_sha1 + test xok = x$(cat $ok) +} + +t_begin "shutdown server" && { + kill -QUIT $rainbows_pid +} + +t_begin "check stderr" && check_stderr + +t_done diff --git a/t/test-lib.sh b/t/test-lib.sh index 655f36b..be654d6 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -198,6 +198,33 @@ req_curl_chunked_upload_err_check () { fi } +check_splice () { + case $(uname -s) in + Linux) ;; + *) + t_info "skipping $T since it's not Linux" + exit 0 + ;; + esac + + # we only allow splice on 2.6.32+ + min=32 uname_r=$(uname -r) + case $uname_r in + 2.6.*) + sub=$(expr "$uname_r" : '2\.6\.\(.*\)$') + if test $sub -lt $min + then + t_info "skipping $T (Linux $(uname_r < 2.6.$min)" + exit 0 + fi + ;; + *) + t_info "skipping $T (Linux $uname_r < 2.6.$min)" + exit 0 + ;; + esac +} + case $model in Rev) require_check rev Rev::VERSION ;; Coolio) require_check coolio Coolio::VERSION ;; diff --git a/t/test_isolate.rb b/t/test_isolate.rb index 3cc646f..fe2aebc 100644 --- a/t/test_isolate.rb +++ b/t/test_isolate.rb @@ -37,7 +37,12 @@ Isolate.now!(opts) do gem 'rack-fiber_pool', '0.9.1' end - gem 'sleepy_penguin', '2.0.0' if RUBY_PLATFORM =~ /linux/ + if RUBY_PLATFORM =~ /linux/ + gem 'sleepy_penguin', '2.0.0' + + # is 2.6.32 new enough? + gem 'io_splice', '4.1.0' if `uname -r`.strip > '2.6.32' + end end $stdout.reopen(old_out) -- cgit v1.2.3-24-ge0c7