Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
@dcarley: Added this sync.Once to prevent two racing go-routines to double close the the channel and panicking.