Skip to content

Commit

Permalink
add goleak
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango committed May 1, 2020
1 parent a4b4a02 commit 4c750ae
Show file tree
Hide file tree
Showing 263 changed files with 2,976 additions and 137 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ tensorflow/install: /usr/local/lib/libtensorflow.so
gentest:
$(call gen-test)


.PHONY: fixtest
## fixtest
fixtest:
$(call fix-test)


.PHONY: test
## run tests
test:
Expand Down
10 changes: 10 additions & 0 deletions Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ define gen-test
find . -type d | \
grep "./cmd\|./hack\|./internal\|./pkg" | \
grep -v "./cmd/cli\| \
./internal/core/ngt\| \
./hack/benchmark/internal/client/ngtd\| \
./hack/benchmark/internal/starter/agent\| \
./hack/benchmark/internal/starter/external\| \
Expand All @@ -114,3 +115,12 @@ define gen-test
done; \
done
endef

define fix-test
find $(ROOTDIR)/internal/k8s/* -name '*_test.go' | xargs sed -i -E "s%k8s.io/apimachinery/pkg/api/errors%github.com/vdaas/vald/internal/errors%g"
find $(ROOTDIR)/* -name '*_test.go' | xargs sed -i -E "s%cockroachdb/errors%vdaas/vald/internal/errors%g"
find $(ROOTDIR)/* -name '*_test.go' | xargs sed -i -E "s%pkg/errors%vdaas/vald/internal/errors%g"
find $(ROOTDIR)/internal/errors -name '*_test.go' | xargs sed -i -E "s%\"github.com/vdaas/vald/internal/errors\"%%g"
find $(ROOTDIR)/internal/errors -name '*_test.go' | xargs sed -i -E "s/errors\.//g"
go mod tidy
endef
1 change: 1 addition & 0 deletions assets/test/templates/common/function.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func {{ .TestName }}(t *testing.T) {
for {{- if (or .Subtests (not .IsNaked)) }} _, test := {{- end }} range tests {
{{- if .Subtests }}
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc({{- if .TestParameters }} test.args {{- end }})
}
Expand Down
1 change: 1 addition & 0 deletions assets/test/templates/common/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ package {{.Package}}
import (
{{range .Imports}}{{.Name}} {{.Path}}
{{end}}
"go.uber.org/goleak"
)
{{end}}
1 change: 1 addition & 0 deletions assets/test/templates/option/function.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func {{ .TestName }}(t *testing.T) {
for {{- if (or .Subtests (not .IsNaked)) }} _, test := {{- end }} range tests {
{{- if .Subtests }}
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc({{- if .TestParameters }} test.args {{- end }})
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/agent/ngt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/discoverer/k8s/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/gateway/vald/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/manager/backup/cassandra/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/manager/backup/mysql/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/manager/compressor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/manager/index/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/manager/replication/agent/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/manager/replication/controller/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/meta/cassandra/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/meta/redis/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package main provides program main
package main

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func Test_main(t *testing.T) {
type want struct {
Expand Down Expand Up @@ -56,6 +60,7 @@ func Test_main(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc()
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ require (
go.uber.org/automaxprocs v1.3.0
go.uber.org/goleak v1.0.0
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9
golang.org/x/tools v0.0.0-20200429213335-127c98bd7927 // indirect
golang.org/x/tools v0.0.0-20200501005904-d351ea090f9b // indirect
gonum.org/v1/hdf5 v0.0.0-20191105085658-fe04b73f3b53
gonum.org/v1/netlib v0.0.0-20200317120129-c5a04cffd98a // indirect
gonum.org/v1/plot v0.7.0
google.golang.org/genproto v0.0.0-20200429120912-1f37eeb960b2
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84
google.golang.org/grpc v1.29.1
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.18.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191203134012-c197fd4bf371/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200429213335-127c98bd7927 h1:qunaQbmBN1l/xZt8mr6MLr8G/IOFiMbXvxYbGVqKlyw=
golang.org/x/tools v0.0.0-20200429213335-127c98bd7927/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200501005904-d351ea090f9b h1:2hSR2MyOaYEy6yJYg/CpErymr/m7xJEJpm9kfT7ZMg4=
golang.org/x/tools v0.0.0-20200501005904-d351ea090f9b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
Expand Down Expand Up @@ -628,8 +628,8 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRn
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200429120912-1f37eeb960b2 h1:fhZC+JJ5NhTWQS4q+Q1p9bkXUduHUDEVxsHM1HGtfDo=
google.golang.org/genproto v0.0.0-20200429120912-1f37eeb960b2/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84 h1:pSLkPbrjnPyLDYUO2VM9mDLqo2V6CFBY84lFSZAfoi4=
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down
8 changes: 7 additions & 1 deletion hack/benchmark/core/benchmark/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
// Package benchmark provides benchmark frame
package benchmark

import "testing"
import (
"testing"

"go.uber.org/goleak"
)

func TestWithName(t *testing.T) {
type T = interface{}
Expand Down Expand Up @@ -95,6 +99,7 @@ func TestWithName(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
Expand Down Expand Up @@ -207,6 +212,7 @@ func TestWithStrategy(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
defer goleak.VerifyNone(t)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
Expand Down
2 changes: 1 addition & 1 deletion hack/benchmark/core/benchmark/strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/vdaas/vald/hack/benchmark/core/benchmark"
"github.com/vdaas/vald/hack/benchmark/internal/assets"
"github.com/vdaas/vald/hack/benchmark/internal/core"
"github.com/vdaas/vald/hack/benchmark/internal/errors"
"github.com/vdaas/vald/internal/errors"
)

type strategy struct {
Expand Down
Loading

0 comments on commit 4c750ae

Please sign in to comment.