Browse Source

remote/storage.go: add a test to highlight a race condition

between Storage.Notify() and Storage.ApplyConfig()

see https://github.com/prometheus/prometheus/issues/12747

Signed-off-by: machine424 <ayoubmrini424@gmail.com>
pull/13135/head
machine424 1 year ago
parent
commit
08c17df244
No known key found for this signature in database
GPG Key ID: A4B001A4FDEE017D
  1. 38
      storage/remote/storage_test.go

38
storage/remote/storage_test.go

@ -14,7 +14,9 @@
package remote package remote
import ( import (
"fmt"
"net/url" "net/url"
"sync"
"testing" "testing"
common_config "github.com/prometheus/common/config" common_config "github.com/prometheus/common/config"
@ -147,3 +149,39 @@ func baseRemoteReadConfig(host string) *config.RemoteReadConfig {
} }
return &cfg return &cfg
} }
// TestWriteStorageApplyConfigsDuringCommit helps detecting races when
// ApplyConfig runs concurrently with Notify
// See https://github.com/prometheus/prometheus/issues/12747
func TestWriteStorageApplyConfigsDuringCommit(t *testing.T) {
s := NewStorage(nil, nil, nil, t.TempDir(), defaultFlushDeadline, nil)
var wg sync.WaitGroup
wg.Add(2000)
start := make(chan struct{})
for i := 0; i < 1000; i++ {
go func(i int) {
<-start
conf := &config.Config{
GlobalConfig: config.DefaultGlobalConfig,
RemoteWriteConfigs: []*config.RemoteWriteConfig{
baseRemoteWriteConfig(fmt.Sprintf("http://test-%d.com", i)),
},
}
require.NoError(t, s.ApplyConfig(conf))
wg.Done()
}(i)
}
for i := 0; i < 1000; i++ {
go func() {
<-start
s.Notify()
wg.Done()
}()
}
close(start)
wg.Wait()
}

Loading…
Cancel
Save