gemspec: set licenses= attribute
[rainbows.git] / t / t0008-ensure-usable-after-limit.sh
blobce15f3b87435403eecb1e98ac33eb37b0d6c5c55
1 #!/bin/sh
2 . ./test-lib.sh
3 test -r random_blob || die "random_blob required, run with 'make $0'"
5 t_plan 14 "ensure we're accounting worker_connections properly"
6 nr=2
8 t_begin "setup" && {
9 rtmpfiles a b c d
10 rainbows_setup $model $nr
11 rainbows -D sha1.ru -c $unicorn_config
12 rainbows_wait_start
15 null_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709
17 t_begin "fire off concurrent processes" && {
19 req='POST / HTTP/1.1\r\n'
20 req="$req"'Host: example.com\r\n'
21 req="$req"'Transfer-Encoding: chunked\r\n\r\n'
23 for i in a b c d
25 rtmpfiles ${i}_fifo ${i}_tmp
26 eval 'i_fifo=$'${i}_fifo
27 eval 'i_tmp=$'${i}_tmp
28 eval "i=$"$i
31 cat $i_fifo > $i_tmp &
32 # need a full HTTP request to get around
33 # httpready
34 printf "$req"
35 sleep 5
36 printf '0\r\n\r\n'
37 wait
38 echo ok > $i
39 ) | socat - TCP:$listen > $i_fifo
40 ) &
41 done
42 wait
45 t_begin "check results" && {
46 for i in a b c d
48 eval 'i_tmp=$'${i}_tmp
49 eval "i=$"$i
50 test xok = x$(cat $i)
51 test x$null_sha1 = x$(tail -1 $i_tmp)
52 done
55 t_begin "repeat concurrent tests with faster clients" && {
56 for i in a b c d
58 eval 'i_tmp=$'${i}_tmp
59 eval "i=$"$i
60 curl -sSf -T- </dev/null http://$listen/ > $i 2> $i_tmp &
61 done
62 wait
65 t_begin "check results" && {
66 for i in a b c d
68 eval 'i_tmp=$'${i}_tmp
69 eval "i=$"$i
70 test ! -s $i_tmp
71 test x$null_sha1 = x$(cat $i)
72 done
75 t_begin "fire off truncated concurrent requests" && {
77 req='POST / HTTP/1.1\r\n'
78 req="$req"'Host: example.com\r\n'
79 req="$req"'Transfer-Encoding: chunked\r\n'
81 for i in a b c d
83 rtmpfiles ${i}_tmp
84 eval 'i_tmp=$'${i}_tmp
85 eval "i=$"$i
88 # need a full HTTP request to get around
89 # httpready
90 printf "$req"
91 echo ok > $i
92 ) | socat - TCP:$listen > $i_tmp
93 ) &
94 done
95 wait
98 t_begin "check broken results" && {
99 for i in a b c d
101 eval 'i_tmp=$'${i}_tmp
102 eval "i=$"$i
103 test xok = x$(cat $i)
104 dbgcat i_tmp
105 done
108 t_begin "repeat concurrent tests with faster clients" && {
109 for i in a b c d
111 eval 'i_tmp=$'${i}_tmp
112 eval "i=$"$i
113 curl -sSf -T- </dev/null http://$listen/ > $i 2> $i_tmp &
114 done
115 wait
118 t_begin "check results" && {
119 for i in a b c d
121 eval 'i_tmp=$'${i}_tmp
122 eval "i=$"$i
123 test ! -s $i_tmp
124 test x$null_sha1 = x$(cat $i)
125 done
128 t_begin "fire off garbage" && {
129 for i in a b c d
131 rtmpfiles ${i}_fifo ${i}_tmp
132 eval 'i_fifo=$'${i}_fifo
133 eval 'i_tmp=$'${i}_tmp
134 eval "i=$"$i
137 cat $i_fifo > $i_tmp &
138 dd if=random_blob bs=4096 count=1
139 wait
140 echo ok > $i
141 ) | socat - TCP:$listen > $i_fifo
143 done
144 wait
147 t_begin "check broken results" && {
148 for i in a b c d
150 eval 'i_tmp=$'${i}_tmp
151 eval "i=$"$i
152 test xok = x$(cat $i)
153 grep -F 'HTTP/1.1 400 Bad Request' $i_tmp
154 done
157 t_begin "repeat concurrent tests with faster clients" && {
158 for i in a b c d
160 eval 'i_tmp=$'${i}_tmp
161 eval "i=$"$i
162 curl -sSf -T- </dev/null http://$listen/ > $i 2> $i_tmp &
163 done
164 wait
167 t_begin "check results" && {
168 for i in a b c d
170 eval 'i_tmp=$'${i}_tmp
171 eval "i=$"$i
172 test ! -s $i_tmp
173 test x$null_sha1 = x$(cat $i)
174 done
177 t_begin "teardown" && {
178 kill $rainbows_pid
181 t_done