Skip to content

Commit

Permalink
Don't close when finishing drawing (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Oct 8, 2020
1 parent 2a36d9a commit 06cefb6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion attacker/attacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func Attack(ctx context.Context, target string, resCh chan *Result, metricsCh ch
select {
case <-ctx.Done():
opts.Attacker.Stop()
// metricsCh is already closed (as context is done) so we shouldn't send any metric
return
default:
resCh <- &Result{Latency: res.Latency}
Expand Down
1 change: 0 additions & 1 deletion gui/drawer.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ End: %v`
)

func (d *drawer) redrawMetrics(ctx context.Context) {
defer close(d.metricsCh)
for {
select {
case <-ctx.Done():
Expand Down
5 changes: 4 additions & 1 deletion gui/drawer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ End: 2009-11-10T23:00:00Z`, gomock.Any())
go d.redrawMetrics(ctx)
d.metricsCh <- tt.metrics
cancel()
<-d.metricsCh
// TODO: Stop waiting inappropriately.
// Currently waiting in a rough manner to ensure that the mock function
// is called in the `redrawMetrics`, but it is unstable and inefficient.
time.Sleep(2 * time.Second)
})
}
}

0 comments on commit 06cefb6

Please sign in to comment.