Skip to content

Using goleak on Go benchmarks. #89

Answered by bwplotka
bwplotka asked this question in Q&A
Discussion options

You must be logged in to vote

Found workaround:

func BenchmarkGoroutines(b *testing.B) {
	defer goleak.VerifyNone(
		b,
		goleak.IgnoreTopFunction("testing.(*B).run1"),
		goleak.IgnoreTopFunction("testing.(*B).doBench"),
	)

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		wg := sync.WaitGroup{}
		wg.Add(2)

		go func() {
			defer wg.Done()
		}()
		go func() {
			defer wg.Done()
		}()

		wg.Wait()
	}
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sywhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #77 on January 10, 2023 09:12.