From 44f62e5e275c8979297967588eefd5092529652d Mon Sep 17 00:00:00 2001 From: caffix Date: Sat, 9 Dec 2017 13:25:28 -0500 Subject: [PATCH] built the WaitForStop functionality into the Stop method --- p2p/trust/metric.go | 16 +++++++--------- p2p/trust/metric_test.go | 2 -- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/p2p/trust/metric.go b/p2p/trust/metric.go index 0ee39a798..3a0bf4809 100644 --- a/p2p/trust/metric.go +++ b/p2p/trust/metric.go @@ -165,8 +165,15 @@ func (tm *TrustMetric) Pause() { } // Stop tells the metric to stop recording data over time intervals +// This method also blocks until the metric has completely stopped func (tm *TrustMetric) Stop() { tm.stop <- struct{}{} + + wait := make(chan struct{}) + + if tm.AddStopWaitChannel(wait) { + <-wait + } } // BadEvents indicates that an undesirable event(s) took place @@ -307,15 +314,6 @@ func (tm *TrustMetric) AddTimeIntervalWaitChannel(interval chan struct{}) bool { return added } -// WaitForStop blocks until the metric has completely stopped -func (tm *TrustMetric) WaitForStop() { - stop := make(chan struct{}) - - if tm.AddStopWaitChannel(stop) { - <-stop - } -} - // SignalStopped fires all the maintained signal channels and sets // metric stopped status to true func (tm *TrustMetric) SignalStopped() { diff --git a/p2p/trust/metric_test.go b/p2p/trust/metric_test.go index 89077e1fa..a83848ced 100644 --- a/p2p/trust/metric_test.go +++ b/p2p/trust/metric_test.go @@ -77,8 +77,6 @@ func TestTrustMetricStopPause(t *testing.T) { tm.NextTimeInterval() tm.NextTimeInterval() tm.Stop() - // Wait for the stop to take place - tm.WaitForStop() second := tm.Copy().numIntervals // Allow more intervals to pass and check that the number of intervals match