diff --git a/go.mod b/go.mod index 4ef90b399..5948b495a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/google/uuid v1.6.0 github.com/jonboulle/clockwork v0.3.0 github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77 + go.uber.org/goleak v1.3.0 golang.org/x/net v0.33.0 golang.org/x/sync v0.10.0 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 @@ -17,18 +18,19 @@ require ( // requires for tests only require ( github.com/rekby/fixenv v0.6.1 - github.com/stretchr/testify v1.7.1 + github.com/stretchr/testify v1.8.0 go.uber.org/mock v0.4.0 ) require ( - github.com/davecgh/go-spew v1.1.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect - gopkg.in/yaml.v3 v3.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) retract v3.67.1 // decimal broken https://github.com/ydb-platform/ydb-go-sdk/issues/1234 diff --git a/go.sum b/go.sum index e63c7c224..d99a653f3 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,10 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -54,6 +56,10 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -61,13 +67,17 @@ github.com/rekby/fixenv v0.6.1 h1:jUFiSPpajT4WY2cYuc++7Y1zWrnCxnovGCIX72PZniM= github.com/rekby/fixenv v0.6.1/go.mod h1:/b5LRc06BYJtslRtHKxsPWFT/ySpHV+rWvzTg+XWk4c= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77 h1:LY6cI8cP4B9rrpTleZk95+08kl2gF4rixG7+V/dwL6Q= github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -146,12 +156,13 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/xtest/leak.go b/internal/xtest/leak.go deleted file mode 100644 index a1081845b..000000000 --- a/internal/xtest/leak.go +++ /dev/null @@ -1,77 +0,0 @@ -package xtest - -import ( - "fmt" - "regexp" - "runtime" - "strings" - "testing" -) - -func findGoroutinesLeak() error { - var bb []byte - for size := 1 << 16; ; size *= 2 { - bb = make([]byte, size) - if n := runtime.Stack(bb, true); n < size { - bb = bb[:n] - - break - } - } - goroutines := strings.Split(string(bb), "\n\n") - unexpectedGoroutines := make([]string, 0, len(goroutines)) - - for i, g := range goroutines { - if i == 0 { - continue - } - stack := strings.Split(g, "\n") - firstFunction := stack[1] - state := strings.Trim( - regexp.MustCompile(`\[.*\]`).FindString( - regexp.MustCompile(`^goroutine \d+ \[.*\]`).FindString(stack[0]), - ), "[]", - ) - switch { - case strings.HasPrefix(firstFunction, "testing.RunTests"), - strings.HasPrefix(firstFunction, "testing.(*T).Run"), - strings.HasPrefix(firstFunction, "testing.(*T).Parallel"), - strings.HasPrefix(firstFunction, "testing.runFuzzing"), - strings.HasPrefix(firstFunction, "testing.runFuzzTests"): - if strings.Contains(state, "chan receive") { - continue - } - - case strings.HasPrefix(firstFunction, "runtime.goexit"): - switch state { - case "syscall", "runnable": - continue - } - - case strings.HasPrefix(firstFunction, "os/signal.signal_recv"), - strings.HasPrefix(firstFunction, "os/signal.loop"): - continue - - case strings.Contains(g, "runtime.ensureSigM"): - continue - - case strings.Contains(g, "runtime.ReadTrace"): - continue - } - - unexpectedGoroutines = append(unexpectedGoroutines, g) - } - if l := len(unexpectedGoroutines); l > 0 { - return fmt.Errorf("found %d unexpected goroutines:\n\n%s", - len(goroutines), strings.Join(goroutines, "\n\n"), - ) - } - - return nil -} - -func CheckGoroutinesLeak(tb testing.TB) { - if err := findGoroutinesLeak(); err != nil { - tb.Errorf("leak goroutines detected: %v", err) - } -} diff --git a/internal/xtest/leak_test.go b/internal/xtest/leak_test.go deleted file mode 100644 index d5f814a3c..000000000 --- a/internal/xtest/leak_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package xtest - -import ( - "sync/atomic" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestCheckGoroutinesLeak(t *testing.T) { - t.Run("Leak", func(t *testing.T) { - TestManyTimes(t, func(t testing.TB) { - var ( - leakDetected atomic.Bool - ch = make(chan struct{}) - ) - func() { - defer func() { - if err := findGoroutinesLeak(); err != nil { - leakDetected.Store(true) - } - }() - go func() { - <-ch - }() - }() - close(ch) - require.True(t, leakDetected.Load()) - }) - }) - t.Run("NoLeak", func(t *testing.T) { - TestManyTimes(t, func(t testing.TB) { - defer func() { - require.NoError(t, findGoroutinesLeak()) - }() - - ch := make(chan struct{}) - go func() { - close(ch) - }() - <-ch - }) - }) -} diff --git a/tests/integration/basic_example_database_sql_bindings_test.go b/tests/integration/basic_example_database_sql_bindings_test.go index 15a00334d..4b5189cf2 100644 --- a/tests/integration/basic_example_database_sql_bindings_test.go +++ b/tests/integration/basic_example_database_sql_bindings_test.go @@ -15,6 +15,7 @@ import ( "time" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc/metadata" "github.com/ydb-platform/ydb-go-sdk/v3" @@ -26,7 +27,7 @@ import ( ) func TestBasicExampleDatabaseSqlBindings(t *testing.T) { - defer xtest.CheckGoroutinesLeak(t) + defer goleak.VerifyNone(t) folder := t.Name() diff --git a/tests/integration/basic_example_database_sql_test.go b/tests/integration/basic_example_database_sql_test.go index d3ed633be..410c9ab1c 100644 --- a/tests/integration/basic_example_database_sql_test.go +++ b/tests/integration/basic_example_database_sql_test.go @@ -16,6 +16,7 @@ import ( "time" "github.com/stretchr/testify/require" + "go.uber.org/goleak" "google.golang.org/grpc/metadata" "github.com/ydb-platform/ydb-go-sdk/v3" @@ -27,7 +28,7 @@ import ( ) func TestBasicExampleDatabaseSql(t *testing.T) { - defer xtest.CheckGoroutinesLeak(t) + defer goleak.VerifyNone(t) folder := t.Name()