Commit c820272
Wait for results before exiting from signal
Previously the attack command would not wait for in-flight requests to
finish before exiting from an interrupt signal. In the case where all
requests take longer than the attack duration then the output file will
be empty and reporting on it will produce an obscure error:
% echo "GET http://172.18.0.254/will/timeout" | time vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out & sleep 1 && pkill -2 vegeta && fg && vegeta report vegeta.out
[1] 12347 12348
[1] + 12347 done echo "GET http://172.18.0.254/will/timeout" |
12348 running time vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out
vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out 0.00s user 0.01s system 0% cpu 1.075 total
2023/01/11 21:35:50 encode: can't detect encoding of "vegeta.out"
By omitting the return on the first call to `Stop()` we can use the
results channel to block the exit until the attack has finished:
% echo "GET http://172.18.0.254/will/timeout" | time ./vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out & sleep 1 && pkill -2 vegeta && fg && ./vegeta report vegeta.out
[1] 12433 12434
[1] + 12433 done echo "GET http://172.18.0.254/will/timeout" |
12434 running time ./vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out
./vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out 0.00s user 0.01s system 0% cpu 11.012 total
Requests [total, rate, throughput] 1, 1.00, 0.00
Duration [total, attack, wait] 10.001s, 0s, 10.001s
Latencies [min, mean, 50, 90, 95, 99, max] 10.001s, 10.001s, 10.001s, 10.001s, 10.001s, 10.001s, 10.001s
Bytes In [total, mean] 0, 0.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 0.00%
Status Codes [code:count] 0:1
Error Set:
Get "http://172.18.0.254/will/timeout": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
A subsequent interrupt signal (ie. `^C^C`) is honoured if you want to
force an immediate exit:
% echo "GET http://172.18.0.254/will/timeout" | time vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out & sleep 1 && pkill -2 vegeta && pkill -2 vegeta && fg
[1] 12073 12074
vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out 0.00s user 0.01s system 1% cpu 1.057 total
[1] + 12073 done echo "GET http://172.18.0.254/will/timeout" |
12074 done time vegeta attack -rate 1 -duration 0 -timeout 10s -output vegeta.out
Testing this required a refactor of `attack()` in order to pass our own
signal channel in. The diff is fortunately pretty simple though. Like
most simple changes and async code, the majority of the changeset is
testing it.
Closes #611
Signed-off-by: Tomás Senart <tsenart@gmail.com>1 parent 3e67d01 commit c820272
3 files changed
+154
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
198 | 207 | | |
199 | 208 | | |
200 | 209 | | |
201 | | - | |
202 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
203 | 214 | | |
204 | 215 | | |
205 | 216 | | |
206 | 217 | | |
207 | | - | |
| 218 | + | |
208 | 219 | | |
209 | 220 | | |
210 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
| 11 | + | |
6 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
7 | 16 | | |
8 | 17 | | |
9 | 18 | | |
| |||
26 | 35 | | |
27 | 36 | | |
28 | 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
325 | 327 | | |
326 | 328 | | |
327 | 329 | | |
328 | | - | |
329 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
330 | 335 | | |
331 | 336 | | |
332 | | - | |
| 337 | + | |
333 | 338 | | |
334 | | - | |
| 339 | + | |
| 340 | + | |
335 | 341 | | |
336 | 342 | | |
337 | 343 | | |
| |||
0 commit comments