Skip to content

Commit

Permalink
[test] Add per-test goleak check for storage/es (#5128)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Part of #5083

## Description of the changes
- Add goleak checks to individual tests suspected of causing the leaks,
this might help confirming which ones are at fault, since the main
VerifyGoLeak check cannot distinguish between tests in the package.

## How was this change tested?
```
$ go test -count 100 ./plugin/storage/es
ok  	github.com/jaegertracing/jaeger/plugin/storage/es	8.246s
```

---------

Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Jan 22, 2024
1 parent da7fd3f commit d687d35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/testutils/leakcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ func IgnoreOpenCensusWorkerLeak() goleak.Option {
}

// VerifyGoLeaks verifies that unit tests do not leak any goroutines.
// It should be called in TestMain.
func VerifyGoLeaks(m *testing.M) {
goleak.VerifyTestMain(m, IgnoreGlogFlushDaemonLeak(), IgnoreOpenCensusWorkerLeak())
}

// VerifyGoLeaksOnce verifies that a given unit test does not leak any goroutines.
// Occasionally useful to troubleshoot specific tests that are flaky due to leaks,
// since VerifyGoLeaks cannot distiguish which specific test caused the leak.
// It should be called via defer or from Cleanup:
//
// defer testutils.VerifyGoLeaksOnce(t)
func VerifyGoLeaksOnce(t *testing.T) {
goleak.VerifyNone(t, IgnoreGlogFlushDaemonLeak(), IgnoreOpenCensusWorkerLeak())
}
4 changes: 4 additions & 0 deletions pkg/testutils/leakcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"testing"
)

func TestVerifyGoLeaksOnce(t *testing.T) {
defer VerifyGoLeaksOnce(t)
}

func TestMain(m *testing.M) {
VerifyGoLeaks(m)
}
2 changes: 2 additions & 0 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func TestInitFromOptions(t *testing.T) {
}

func TestPasswordFromFile(t *testing.T) {
defer testutils.VerifyGoLeaksOnce(t)
t.Run("primary client", func(t *testing.T) {
f := NewFactory()
testPasswordFromFile(t, f, f.getPrimaryClient, f.CreateSpanWriter)
Expand Down Expand Up @@ -375,6 +376,7 @@ func TestFactoryESClientsAreNil(t *testing.T) {
}

func TestPasswordFromFileErrors(t *testing.T) {
defer testutils.VerifyGoLeaksOnce(t)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(mockEsServerResponse)
}))
Expand Down

0 comments on commit d687d35

Please sign in to comment.