Skip to content

Commit

Permalink
fix gmeasure leak
Browse files Browse the repository at this point in the history
  • Loading branch information
onsi committed Sep 19, 2022
1 parent ba548e2 commit 119d4ce
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gexec/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ var _ = Describe(".CompiledTestIn", func() {
}
})

Context("a remote package", Label("remote"), func() {
Context("a remote package", Label("network"), func() {
const remotePackage = "github.com/onsi/ginkgo/types"

It("compiles the specified test package", func() {
Expand Down
1 change: 1 addition & 0 deletions gmeasure/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ func (e *Experiment) Sample(callback func(idx int), samplingConfig SamplingConfi
minSamplingInterval := samplingConfig.MinSamplingInterval

work := make(chan int)
defer close(work)
if numParallel > 1 {
for worker := 0; worker < numParallel; worker++ {
go func() {
Expand Down
4 changes: 4 additions & 0 deletions gmeasure/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/onsi/gomega/gleak"
"github.com/onsi/gomega/gmeasure"
)

Expand Down Expand Up @@ -224,6 +225,7 @@ var _ = Describe("Experiment", func() {
})

It("can run samples in parallel", func() {
g := gleak.Goroutines()
lock := &sync.Mutex{}

e.Sample(func(idx int) {
Expand All @@ -237,6 +239,8 @@ 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() {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ require (
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)

replace github.com/onsi/ginkgo/v2 => ../ginkgo

0 comments on commit 119d4ce

Please sign in to comment.