summary refs log tree commit homepage
path: root/t/t0008-ensure-usable-after-limit.sh
blob: ce15f3b87435403eecb1e98ac33eb37b0d6c5c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/sh
. ./test-lib.sh
test -r random_blob || die "random_blob required, run with 'make $0'"

t_plan 14 "ensure we're accounting worker_connections properly"
nr=2

t_begin "setup" && {
	rtmpfiles a b c d
	rainbows_setup $model $nr
	rainbows -D sha1.ru -c $unicorn_config
	rainbows_wait_start
}

null_sha1=da39a3ee5e6b4b0d3255bfef95601890afd80709

t_begin "fire off concurrent processes" && {

	req='POST / HTTP/1.1\r\n'
	req="$req"'Host: example.com\r\n'
	req="$req"'Transfer-Encoding: chunked\r\n\r\n'

	for i in a b c d
	do
		rtmpfiles ${i}_fifo ${i}_tmp
		eval 'i_fifo=$'${i}_fifo
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		(
			(
				cat $i_fifo > $i_tmp &
				# need a full HTTP request to get around
				# httpready
				printf "$req"
				sleep 5
				printf '0\r\n\r\n'
				wait
				echo ok > $i
			) | socat - TCP:$listen > $i_fifo
		) &
	done
	wait
}

t_begin "check results" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		test xok = x$(cat $i)
		test x$null_sha1 = x$(tail -1 $i_tmp)
	done
}

t_begin "repeat concurrent tests with faster clients" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		curl -sSf -T- </dev/null http://$listen/ > $i 2> $i_tmp &
	done
	wait
}

t_begin "check results" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		test ! -s $i_tmp
		test x$null_sha1 = x$(cat $i)
	done
}

t_begin "fire off truncated concurrent requests" && {

	req='POST / HTTP/1.1\r\n'
	req="$req"'Host: example.com\r\n'
	req="$req"'Transfer-Encoding: chunked\r\n'

	for i in a b c d
	do
		rtmpfiles ${i}_tmp
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		(
			(
				# need a full HTTP request to get around
				# httpready
				printf "$req"
				echo ok > $i
			) | socat - TCP:$listen > $i_tmp
		) &
	done
	wait
}

t_begin "check broken results" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		test xok = x$(cat $i)
		dbgcat i_tmp
	done
}

t_begin "repeat concurrent tests with faster clients" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		curl -sSf -T- </dev/null http://$listen/ > $i 2> $i_tmp &
	done
	wait
}

t_begin "check results" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		test ! -s $i_tmp
		test x$null_sha1 = x$(cat $i)
	done
}

t_begin "fire off garbage" && {
	for i in a b c d
	do
		rtmpfiles ${i}_fifo ${i}_tmp
		eval 'i_fifo=$'${i}_fifo
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		(
			(
				cat $i_fifo > $i_tmp &
				dd if=random_blob bs=4096 count=1
				wait
				echo ok > $i
			) | socat - TCP:$listen > $i_fifo
		) &
	done
	wait
}

t_begin "check broken results" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		test xok = x$(cat $i)
		grep -F 'HTTP/1.1 400 Bad Request' $i_tmp
	done
}

t_begin "repeat concurrent tests with faster clients" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		curl -sSf -T- </dev/null http://$listen/ > $i 2> $i_tmp &
	done
	wait
}

t_begin "check results" && {
	for i in a b c d
	do
		eval 'i_tmp=$'${i}_tmp
		eval "i=$"$i
		test ! -s $i_tmp
		test x$null_sha1 = x$(cat $i)
	done
}

t_begin "teardown" && {
	kill $rainbows_pid
}

t_done