From 8c54344b7bc6a1091fe7f1b674ae1cb9cccc850a Mon Sep 17 00:00:00 2001 From: Onsi Fakhouri Date: Mon, 19 Sep 2022 11:39:52 -0600 Subject: [PATCH] cover the entire gmeasure suite with leak detection --- gmeasure/experiment_test.go | 4 ---- gmeasure/gmeasure_suite_test.go | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/gmeasure/experiment_test.go b/gmeasure/experiment_test.go index d0647272f..9a8745c08 100644 --- a/gmeasure/experiment_test.go +++ b/gmeasure/experiment_test.go @@ -9,7 +9,6 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/onsi/gomega/gleak" "github.com/onsi/gomega/gmeasure" ) @@ -225,7 +224,6 @@ var _ = Describe("Experiment", func() { }) It("can run samples in parallel", func() { - g := gleak.Goroutines() lock := &sync.Mutex{} e.Sample(func(idx int) { @@ -239,8 +237,6 @@ var _ = Describe("Experiment", func() { defer lock.Unlock() Ω(len(indices)).Should(BeNumerically("~", 30, 10)) Ω(indices).Should(ConsistOf(ints(len(indices)))) - - Eventually(gleak.Goroutines).ShouldNot(gleak.HaveLeaked(g)) }) It("panics if the SamplingConfig does not specify a ceiling", func() { diff --git a/gmeasure/gmeasure_suite_test.go b/gmeasure/gmeasure_suite_test.go index d9a664621..2c953fbaf 100644 --- a/gmeasure/gmeasure_suite_test.go +++ b/gmeasure/gmeasure_suite_test.go @@ -5,9 +5,17 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/onsi/gomega/gleak" ) func TestGmeasure(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Gmeasure Suite") } + +var _ = BeforeEach(func() { + g := gleak.Goroutines() + DeferCleanup(func() { + Eventually(gleak.Goroutines).ShouldNot(gleak.HaveLeaked(g)) + }) +})