Goleak in discoveries, scrape, rules (#7662)

* Add go leak tests for discoveries with goroutines

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>

* Add go leak tests in rules

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>

* Add go leak tests in scrape tests

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
Julien Pivotto 2020-07-27 10:38:08 +02:00 committed by GitHub
parent e07415227a
commit e76c436e9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 0 deletions

View file

@ -18,8 +18,13 @@ import (
"testing" "testing"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"go.uber.org/goleak"
) )
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestMapFromVMWithEmptyTags(t *testing.T) { func TestMapFromVMWithEmptyTags(t *testing.T) {
id := "test" id := "test"
name := "name" name := "name"

View file

@ -22,6 +22,7 @@ import (
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/miekg/dns" "github.com/miekg/dns"
"go.uber.org/goleak"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
@ -29,6 +30,10 @@ import (
"github.com/prometheus/prometheus/util/testutil" "github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestDNS(t *testing.T) { func TestDNS(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string

View file

@ -26,11 +26,16 @@ import (
"time" "time"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"go.uber.org/goleak"
"github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/util/testutil" "github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
const defaultWait = time.Second const defaultWait = time.Second
type testRunner struct { type testRunner struct {

View file

@ -29,6 +29,10 @@ import (
"github.com/prometheus/prometheus/util/testutil" "github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) {
testutil.TolerantVerifyLeak(m)
}
// makeDiscovery creates a kubernetes.Discovery instance for testing. // makeDiscovery creates a kubernetes.Discovery instance for testing.
func makeDiscovery(role Role, nsDiscovery NamespaceDiscovery, objects ...runtime.Object) (*Discovery, kubernetes.Interface) { func makeDiscovery(role Role, nsDiscovery NamespaceDiscovery, objects ...runtime.Object) (*Discovery, kubernetes.Interface) {
clientset := fake.NewSimpleClientset(objects...) clientset := fake.NewSimpleClientset(objects...)

View file

@ -20,11 +20,16 @@ import (
"time" "time"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"go.uber.org/goleak"
"github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/util/testutil" "github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestRefresh(t *testing.T) { func TestRefresh(t *testing.T) {
tg1 := []*targetgroup.Group{ tg1 := []*targetgroup.Group{
{ {

View file

@ -18,8 +18,13 @@ import (
"time" "time"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"go.uber.org/goleak"
) )
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestNewDiscoveryError(t *testing.T) { func TestNewDiscoveryError(t *testing.T) {
_, err := NewDiscovery( _, err := NewDiscovery(
[]string{"unreachable.test"}, []string{"unreachable.test"},

View file

@ -26,6 +26,7 @@ import (
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"go.uber.org/goleak"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
"github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/labels"
@ -39,6 +40,10 @@ import (
"github.com/prometheus/prometheus/util/testutil" "github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}
func TestAlertingRule(t *testing.T) { func TestAlertingRule(t *testing.T) {
suite, err := promql.NewTest(t, ` suite, err := promql.NewTest(t, `
load 5m load 5m

View file

@ -46,6 +46,10 @@ import (
"github.com/prometheus/prometheus/util/testutil" "github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) {
testutil.TolerantVerifyLeak(m)
}
func TestNewScrapePool(t *testing.T) { func TestNewScrapePool(t *testing.T) {
var ( var (
app = &nopAppendable{} app = &nopAppendable{}
@ -1785,6 +1789,7 @@ func TestReuseScrapeCache(t *testing.T) {
} }
proxyURL, _ = url.Parse("http://localhost:2128") proxyURL, _ = url.Parse("http://localhost:2128")
) )
defer sp.stop()
sp.sync([]*Target{t1}) sp.sync([]*Target{t1})
steps := []struct { steps := []struct {
@ -1937,6 +1942,7 @@ func TestReuseCacheRace(t *testing.T) {
}, },
} }
) )
defer sp.stop()
sp.sync([]*Target{t1}) sp.sync([]*Target{t1})
start := time.Now() start := time.Now()