From 46e6d7cc9bf4a3f1df41b167522f3cad6bd3a7e9 Mon Sep 17 00:00:00 2001 From: Dan Gottlieb Date: Tue, 29 Oct 2024 10:51:32 -0400 Subject: [PATCH] =?UTF-8?q?Revert=20"DATA-2663=20-=20Reduce=20goroutine=20?= =?UTF-8?q?leaks=20while=20running=20local=20tests=20=E2=80=A6=20(#379)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testutils/ext/verify.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/testutils/ext/verify.go b/testutils/ext/verify.go index 2a407ee0..8e35637e 100644 --- a/testutils/ext/verify.go +++ b/testutils/ext/verify.go @@ -3,11 +3,17 @@ package testutilsext import ( + "context" "fmt" + "net/http" "os" + "runtime" + "time" "github.com/edaniels/golog" "go.uber.org/goleak" + "google.golang.org/api/option" + "google.golang.org/api/transport" "go.viam.com/utils" "go.viam.com/utils/artifact" @@ -16,11 +22,32 @@ import ( // VerifyTestMain preforms various runtime checks on code that tests run. func VerifyTestMain(m goleak.TestingM) { + func() { + // workaround https://github.com/googleapis/google-cloud-go/issues/5430 + httpClient := &http.Client{Transport: http.DefaultTransport.(*http.Transport).Clone()} + defer httpClient.CloseIdleConnections() + + //nolint:errcheck + _, _ = transport.Creds(context.Background(), option.WithHTTPClient(httpClient)) + + t := time.NewTimer(100 * time.Millisecond) + defer t.Stop() + for { + select { + case <-t.C: + return + default: + runtime.Gosched() + } + } + }() + + currentGoroutines := goleak.IgnoreCurrent() + cache, err := artifact.GlobalCache() if err != nil { golog.Global().Fatalw("error opening artifact", "error", err) } - currentGoroutines := goleak.IgnoreCurrent() //nolint:ifshort exitCode := m.Run() testutils.Teardown()