fiber/base: use bare "select" where possible
[rainbows.git] / t / t0022-copy_stream-byte-range.sh
blobdd718934e5e743f5897f6e222193225bbe63f980
1 #!/bin/sh
2 . ./test-lib.sh
3 test -r random_blob || die "random_blob required, run with 'make $0'"
4 case $RUBY_VERSION in
5 1.9.*) ;;
6 *)
7 t_info "skipping $T since it can't IO.copy_stream"
8 exit 0
9 ;;
10 esac
12 case $model in
13 ThreadSpawn|WriterThreadSpawn|ThreadPool|WriterThreadPool|Base) ;;
15 t_info "skipping $T since it doesn't use IO.copy_stream"
16 exit 0
18 esac
20 t_plan 11 "IO.copy_stream byte range response for $model"
22 t_begin "setup and startup" && {
23 rtmpfiles out err
24 rainbows_setup $model
25 # can't load Rack::Lint here since it clobbers body#to_path
26 rainbows -E none -D large-file-response.ru -c $unicorn_config
27 rainbows_wait_start
28 random_blob_size=$(wc -c < random_blob)
29 rb_1=$(( $random_blob_size - 1 ))
30 range_head=-r-365
31 range_tail=-r155-
32 range_mid=-r200-300
33 range_n1=-r0-$rb_1
34 range_n2=-r0-$(($rb_1 - 1))
35 range_1b_head=-r0-0
36 range_1b_tail=-r$rb_1-$rb_1
37 range_1b_mid=-r200-200
38 range_all=-r0-$random_blob_size
39 url=http://$listen/random_blob
42 check_content_range () {
43 # Content-Range: bytes #{offset}-#{offset+count-1}/#{clen}
44 awk -F/ -v E=0 -v size=$random_blob_size '
45 $2 == size && /^< Content-Range: bytes [0-9]+-[0-9]+\// {
46 split($1, a, /-/);
47 if (a[1] < size) {
48 E = 0;
49 exit(0);
52 END { exit(E) }
53 ' < $err
56 t_begin "read random blob sha1s" && {
57 sha1_head=$(curl -sSff $range_head file://random_blob | rsha1)
58 sha1_tail=$(curl -sSff $range_tail file://random_blob | rsha1)
59 sha1_mid=$(curl -sSff $range_mid file://random_blob | rsha1)
60 sha1_n1=$(curl -sSff $range_n1 file://random_blob | rsha1)
61 sha1_n2=$(curl -sSff $range_n2 file://random_blob | rsha1)
62 sha1_1b_head=$(curl -sSff $range_1b_head file://random_blob | rsha1)
63 sha1_1b_tail=$(curl -sSff $range_1b_tail file://random_blob | rsha1)
64 sha1_1b_mid=$(curl -sSff $range_1b_mid file://random_blob | rsha1)
65 sha1_all=$(rsha1 < random_blob)
66 echo "$sha1_all=$sha1_n1"
69 t_begin "normal full request matches" && {
70 sha1="$(curl -v 2>$err -sSf $url | rsha1)"
71 test x"$sha1_all" = x"$sha1"
72 grep 'Content-Range:' $err && die "Content-Range unexpected"
73 grep 'HTTP/1.1 200 OK' $err || die "200 response expected"
76 t_begin "crazy offset goes over" && {
77 range_insane=-r$(($random_blob_size * 2))-$(($random_blob_size * 4))
78 curl -vsS 2>$err $range_insane $url
79 grep 'HTTP/1\.[01] 416 ' $err || die "expected 416 error"
82 t_begin "full request matches with explicit ranges" && {
83 sha1="$(curl -v 2>$err $range_all -sSf $url | rsha1)"
84 check_content_range
85 test x"$sha1_all" = x"$sha1"
87 sha1="$(curl -v 2>$err $range_n1 -sSf $url | rsha1)"
88 check_content_range
89 test x"$sha1_all" = x"$sha1"
91 range_over=-r0-$(($random_blob_size * 2))
92 sha1="$(curl -v 2>$err $range_over -sSf $url | rsha1)"
93 check_content_range
94 test x"$sha1_all" = x"$sha1"
97 t_begin "no fence post errors" && {
98 sha1="$(curl -v 2>$err $range_n2 -sSf $url | rsha1)"
99 check_content_range
100 test x"$sha1_n2" = x"$sha1"
102 sha1="$(curl -v 2>$err $range_1b_head -sSf $url | rsha1)"
103 check_content_range
104 test x"$sha1_1b_head" = x"$sha1"
106 sha1="$(curl -v 2>$err $range_1b_tail -sSf $url | rsha1)"
107 check_content_range
108 test x"$sha1_1b_tail" = x"$sha1"
110 sha1="$(curl -v 2>$err $range_1b_mid -sSf $url | rsha1)"
111 check_content_range
112 test x"$sha1_1b_mid" = x"$sha1"
115 t_begin "head range matches" && {
116 sha1="$(curl -sSfv $range_head $url | rsha1)"
117 check_content_range
118 test x"$sha1_head" = x"$sha1"
121 t_begin "tail range matches" && {
122 sha1="$(curl -sSf $range_tail $url | rsha1)"
123 check_content_range
124 test x"$sha1_tail" = x"$sha1"
127 t_begin "mid range matches" && {
128 sha1="$(curl -sSf $range_mid $url | rsha1)"
129 check_content_range
130 test x"$sha1_mid" = x"$sha1"
133 t_begin "shutdown server" && {
134 kill -QUIT $rainbows_pid
137 t_begin "check stderr" && check_stderr
139 t_done