Skip to content

Commit

Permalink
Make it possible to stop attacking
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Sep 12, 2020
1 parent 5ab1a75 commit 57b25da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions attacker/attacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Result struct {
// Results are sent to the given channel as soon as they arrive.
// When the attack is over, it gives back final statistics.
func Attack(ctx context.Context, target string, resCh chan *Result, opts Options) *Metrics {
pp.Println("start attacking")
if opts.Rate == 0 {
opts.Rate = defaultRate
}
Expand All @@ -59,12 +58,13 @@ func Attack(ctx context.Context, target string, resCh chan *Result, opts Options
var metrics vegeta.Metrics

for res := range attacker.Attack(targeter, rate, opts.Duration, "main") {
// TODO: Stop if ctx is expired.
/*if <-ctx.Done() {
return newMetrics(&metrics)
}*/
resCh <- &Result{Latency: res.Latency}
metrics.Add(res)
select {
case <-ctx.Done():
attacker.Stop()
default:
resCh <- &Result{Latency: res.Latency}
metrics.Add(res)
}
}
metrics.Close()
pp.Println("vegeta metrics", metrics)
Expand Down
2 changes: 1 addition & 1 deletion gui/widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func redrawChart(ctx context.Context, lineChart *linechart.LineChart, resultCh c
lineChart.Series("plot", values,
linechart.SeriesCellOpts(cell.FgColor(cell.ColorNumber(87))),
linechart.SeriesXLabels(map[int]string{
0: "zero",
0: "num",
}),
)
}
Expand Down

0 comments on commit 57b25da

Please sign in to comment.