mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
Remove race condition from TestRetentionCutoff
This commit is contained in:
parent
90b9fae638
commit
9a3edea477
|
@ -132,6 +132,7 @@ type memorySeriesStorage struct {
|
||||||
options *MemorySeriesStorageOptions
|
options *MemorySeriesStorageOptions
|
||||||
|
|
||||||
loopStopping, loopStopped chan struct{}
|
loopStopping, loopStopped chan struct{}
|
||||||
|
logThrottlingStopped chan struct{}
|
||||||
maxMemoryChunks int
|
maxMemoryChunks int
|
||||||
dropAfter time.Duration
|
dropAfter time.Duration
|
||||||
checkpointInterval time.Duration
|
checkpointInterval time.Duration
|
||||||
|
@ -181,6 +182,7 @@ func NewMemorySeriesStorage(o *MemorySeriesStorageOptions) Storage {
|
||||||
|
|
||||||
loopStopping: make(chan struct{}),
|
loopStopping: make(chan struct{}),
|
||||||
loopStopped: make(chan struct{}),
|
loopStopped: make(chan struct{}),
|
||||||
|
logThrottlingStopped: make(chan struct{}),
|
||||||
throttled: make(chan struct{}, 1),
|
throttled: make(chan struct{}, 1),
|
||||||
maxMemoryChunks: o.MemoryChunks,
|
maxMemoryChunks: o.MemoryChunks,
|
||||||
dropAfter: o.PersistenceRetentionPeriod,
|
dropAfter: o.PersistenceRetentionPeriod,
|
||||||
|
@ -640,6 +642,9 @@ func (s *memorySeriesStorage) logThrottling() {
|
||||||
timer := time.NewTimer(time.Minute)
|
timer := time.NewTimer(time.Minute)
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
|
|
||||||
|
// Signal exit of the goroutine. Currently only needed by test code.
|
||||||
|
defer close(s.logThrottlingStopped)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.throttled:
|
case <-s.throttled:
|
||||||
|
|
|
@ -379,6 +379,7 @@ func TestRetentionCutoff(t *testing.T) {
|
||||||
// Stop maintenance loop to prevent actual purging.
|
// Stop maintenance loop to prevent actual purging.
|
||||||
close(s.loopStopping)
|
close(s.loopStopping)
|
||||||
<-s.loopStopped
|
<-s.loopStopped
|
||||||
|
<-s.logThrottlingStopped
|
||||||
// Recreate channel to avoid panic when we really shut down.
|
// Recreate channel to avoid panic when we really shut down.
|
||||||
s.loopStopping = make(chan struct{})
|
s.loopStopping = make(chan struct{})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue