From 06cefb699e321da7a7acc8d850b1bcf265e5f7f7 Mon Sep 17 00:00:00 2001 From: Ryo Nakao Date: Thu, 8 Oct 2020 21:54:07 +0900 Subject: [PATCH] Don't close when finishing drawing (#55) --- attacker/attacker.go | 1 - gui/drawer.go | 1 - gui/drawer_test.go | 5 ++++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/attacker/attacker.go b/attacker/attacker.go index 8921de4..c11e1d0 100644 --- a/attacker/attacker.go +++ b/attacker/attacker.go @@ -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} diff --git a/gui/drawer.go b/gui/drawer.go index fa2c8ac..d853eae 100644 --- a/gui/drawer.go +++ b/gui/drawer.go @@ -101,7 +101,6 @@ End: %v` ) func (d *drawer) redrawMetrics(ctx context.Context) { - defer close(d.metricsCh) for { select { case <-ctx.Done(): diff --git a/gui/drawer_test.go b/gui/drawer_test.go index 2a02731..d20557f 100644 --- a/gui/drawer_test.go +++ b/gui/drawer_test.go @@ -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) }) } }