Browse Source

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>
pull/7678/head
Julien Pivotto 4 years ago committed by GitHub
parent
commit
e76c436e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      discovery/azure/azure_test.go
  2. 5
      discovery/dns/dns_test.go
  3. 5
      discovery/file/file_test.go
  4. 4
      discovery/kubernetes/kubernetes_test.go
  5. 5
      discovery/refresh/refresh_test.go
  6. 5
      discovery/zookeeper/zookeeper_test.go
  7. 5
      rules/manager_test.go
  8. 6
      scrape/scrape_test.go

5
discovery/azure/azure_test.go

@ -18,8 +18,13 @@ import (
"testing"
"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) {
id := "test"
name := "name"

5
discovery/dns/dns_test.go

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

5
discovery/file/file_test.go

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

4
discovery/kubernetes/kubernetes_test.go

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

5
discovery/refresh/refresh_test.go

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

5
discovery/zookeeper/zookeeper_test.go

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

5
rules/manager_test.go

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

6
scrape/scrape_test.go

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

Loading…
Cancel
Save