coolio_thread_*: fix 416 response handling
[rainbows.git] / t / byte-range-common.sh
blob120aad62702563ae336bdb12ca3ed4be4386f8af
1 t_begin "byte-range setup vars" && {
2 random_blob_size=$(wc -c < random_blob)
3 rb_1=$(( $random_blob_size - 1 ))
4 range_head=-r-365
5 range_tail=-r155-
6 range_mid=-r200-300
7 range_n1=-r0-$rb_1
8 range_n2=-r0-$(($rb_1 - 1))
9 range_1b_head=-r0-0
10 range_1b_tail=-r$rb_1-$rb_1
11 range_1b_mid=-r200-200
12 range_all=-r0-$random_blob_size
13 url=http://$listen/random_blob
16 check_content_range () {
17 grep 'Range:' $err
18 # Content-Range: bytes #{offset}-#{offset+count-1}/#{clen}
19 d='\([0-9]\+\)'
20 start= end= size=
21 eval $(< $err sed -n -e \
22 "s/^< Content-Range: bytes $d-$d\/$d"'.*$/start=\1 end=\2 size=\3/p')
23 test -n "$start"
24 test -n "$end"
25 test -n "$size"
27 # ensure we didn't screw up the sed invocation
28 expect="< Content-Range: bytes $start-$end/$size"
29 test x"$(grep -F "$expect" $err)" = x"$(grep '^< Content-Range:' $err)"
31 test $start -le $end
32 test $end -lt $size
35 t_begin "read random blob sha1s" && {
36 sha1_head=$(curl -sSff $range_head file://random_blob | rsha1)
37 sha1_tail=$(curl -sSff $range_tail file://random_blob | rsha1)
38 sha1_mid=$(curl -sSff $range_mid file://random_blob | rsha1)
39 sha1_n1=$(curl -sSff $range_n1 file://random_blob | rsha1)
40 sha1_n2=$(curl -sSff $range_n2 file://random_blob | rsha1)
41 sha1_1b_head=$(curl -sSff $range_1b_head file://random_blob | rsha1)
42 sha1_1b_tail=$(curl -sSff $range_1b_tail file://random_blob | rsha1)
43 sha1_1b_mid=$(curl -sSff $range_1b_mid file://random_blob | rsha1)
44 sha1_all=$(rsha1 < random_blob)
45 echo "$sha1_all=$sha1_n1"
48 t_begin "normal full request matches" && {
49 sha1="$(curl -v 2>$err -sSf $url | rsha1)"
50 test x"$sha1_all" = x"$sha1"
51 grep 'Content-Range:' $err && die "Content-Range unexpected"
52 grep 'HTTP/1.1 200 OK' $err || die "200 response expected"
55 t_begin "crazy offset goes over" && {
56 range_insane=-r$(($random_blob_size * 2))-$(($random_blob_size * 4))
57 curl -vsS 2>$err $range_insane $url
58 grep 'HTTP/1\.[01] 416 ' $err || die "expected 416 error"
61 t_begin "full request matches with explicit ranges" && {
62 sha1="$(curl -v 2>$err $range_all -sSf $url | rsha1)"
63 check_content_range
64 test x"$sha1_all" = x"$sha1"
66 sha1="$(curl -v 2>$err $range_n1 -sSf $url | rsha1)"
67 check_content_range
68 test x"$sha1_all" = x"$sha1"
70 range_over=-r0-$(($random_blob_size * 2))
71 sha1="$(curl -v 2>$err $range_over -sSf $url | rsha1)"
72 check_content_range
73 test x"$sha1_all" = x"$sha1"
76 t_begin "no fence post errors" && {
77 sha1="$(curl -v 2>$err $range_n2 -sSf $url | rsha1)"
78 check_content_range
79 test x"$sha1_n2" = x"$sha1"
81 sha1="$(curl -v 2>$err $range_1b_head -sSf $url | rsha1)"
82 check_content_range
83 test x"$sha1_1b_head" = x"$sha1"
85 sha1="$(curl -v 2>$err $range_1b_tail -sSf $url | rsha1)"
86 check_content_range
87 test x"$sha1_1b_tail" = x"$sha1"
89 sha1="$(curl -v 2>$err $range_1b_mid -sSf $url | rsha1)"
90 check_content_range
91 test x"$sha1_1b_mid" = x"$sha1"
94 t_begin "head range matches" && {
95 sha1="$(curl -sSfv 2>$err $range_head $url | rsha1)"
96 check_content_range
97 test x"$sha1_head" = x"$sha1"
100 t_begin "tail range matches" && {
101 sha1="$(curl -sSfv 2>$err $range_tail $url | rsha1)"
102 check_content_range
103 test x"$sha1_tail" = x"$sha1"
106 t_begin "mid range matches" && {
107 sha1="$(curl -sSfv 2>$err $range_mid $url | rsha1)"
108 check_content_range
109 test x"$sha1_mid" = x"$sha1"
112 t_begin "shutdown server" && {
113 kill -QUIT $rainbows_pid
116 t_begin "check stderr" && check_stderr
118 t_done