From 9a3edea477ae1328ff06d3905afefb4389b861f3 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Fri, 12 Feb 2016 01:46:18 +0100 Subject: [PATCH] Remove race condition from TestRetentionCutoff --- storage/local/storage.go | 5 +++++ storage/local/storage_test.go | 1 + 2 files changed, 6 insertions(+) diff --git a/storage/local/storage.go b/storage/local/storage.go index b74c27cbd..f828c01fd 100644 --- a/storage/local/storage.go +++ b/storage/local/storage.go @@ -132,6 +132,7 @@ type memorySeriesStorage struct { options *MemorySeriesStorageOptions loopStopping, loopStopped chan struct{} + logThrottlingStopped chan struct{} maxMemoryChunks int dropAfter time.Duration checkpointInterval time.Duration @@ -181,6 +182,7 @@ func NewMemorySeriesStorage(o *MemorySeriesStorageOptions) Storage { loopStopping: make(chan struct{}), loopStopped: make(chan struct{}), + logThrottlingStopped: make(chan struct{}), throttled: make(chan struct{}, 1), maxMemoryChunks: o.MemoryChunks, dropAfter: o.PersistenceRetentionPeriod, @@ -640,6 +642,9 @@ func (s *memorySeriesStorage) logThrottling() { timer := time.NewTimer(time.Minute) timer.Stop() + // Signal exit of the goroutine. Currently only needed by test code. + defer close(s.logThrottlingStopped) + for { select { case <-s.throttled: diff --git a/storage/local/storage_test.go b/storage/local/storage_test.go index 701a56f38..74bb63153 100644 --- a/storage/local/storage_test.go +++ b/storage/local/storage_test.go @@ -379,6 +379,7 @@ func TestRetentionCutoff(t *testing.T) { // Stop maintenance loop to prevent actual purging. close(s.loopStopping) <-s.loopStopped + <-s.logThrottlingStopped // Recreate channel to avoid panic when we really shut down. s.loopStopping = make(chan struct{})