Commit 98ff11d
authored
Fix flaky test test_horrible_queries (#3857)
`test_horrible_queries` can be flaky, but it's very hard to detect.
This commit fixes the flakiness. To understand the flakiness, let me
put the original test code below:
```ruby
# then that large mangled field values are caught
10.times do |c|
get = "GET /#{rand_data(10,120)} HTTP/1.1\r\nX-Test: #{rand_data(1024, 1024+(c*1024), false)}\r\n\r\n"
assert_raises Puma::HttpParserError do
parser.execute({}, get, 0)
parser.reset
end
end
```
The way I understand `rand_data(xxx, false)` is that the function should
_always_ return invalid bytes (IOW cause the parser to raise an
exception).
However, it is possible for that function to _sometimes_ return valid
bytes. The above test asserts that an error is raised when
`parser.execute` is called, but if an exception gets raised, then
`parser.reset` isn't called. If `parser.reset` isn't called, then
subsequent calls to `parser.execute` will raise an exception
_regardless_ of whether the input is parse-able or not. In other words,
if the first iteration caused an exception, subsequent iterations are
guaranteed to raise an exception.
This commit does two things:
1. Pulls `parser.reset` outside of the assert_raises so that the flake
is more obvious / reproducible
2. Changes `rand_data` to always add an invalid byte so that if the
random data happens to contain parsable data, we'll at least have one
byte guaranteed to fail.1 parent da162d7 commit 98ff11d
1 file changed
Lines changed: 9 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| |||
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
211 | | - | |
212 | 214 | | |
| 215 | + | |
213 | 216 | | |
214 | 217 | | |
215 | 218 | | |
| |||
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
223 | | - | |
224 | 226 | | |
| 227 | + | |
225 | 228 | | |
226 | 229 | | |
227 | 230 | | |
228 | 231 | | |
229 | 232 | | |
230 | 233 | | |
231 | 234 | | |
232 | | - | |
233 | 235 | | |
| 236 | + | |
234 | 237 | | |
235 | 238 | | |
236 | 239 | | |
237 | 240 | | |
238 | 241 | | |
239 | 242 | | |
240 | 243 | | |
241 | | - | |
242 | 244 | | |
| 245 | + | |
243 | 246 | | |
244 | 247 | | |
245 | 248 | | |
246 | 249 | | |
247 | 250 | | |
248 | 251 | | |
249 | | - | |
250 | 252 | | |
| 253 | + | |
251 | 254 | | |
252 | 255 | | |
253 | 256 | | |
| |||
0 commit comments