Skip to content

Commit

Permalink
Revert "DATA-2663 - Reduce goroutine leaks while running local tests … (
Browse files Browse the repository at this point in the history
  • Loading branch information
dgottlieb authored Oct 29, 2024
1 parent f147ffb commit 46e6d7c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion testutils/ext/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand Down

0 comments on commit 46e6d7c

Please sign in to comment.