Skip to content

Commit

Permalink
Merge pull request #738 from knabben/leak-stop
Browse files Browse the repository at this point in the history
🏃 Verification of leak goroutine on controller and manager
  • Loading branch information
k8s-ci-robot committed Feb 6, 2020
2 parents b97ebda + 87a0264 commit 82a78f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ package controller_test

import (
"fmt"
rt "runtime"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -90,6 +92,27 @@ var _ = Describe("controller.Controller", func() {

close(done)
})

It("should not leak goroutines when stop", func(done Done) {
// TODO(directxman12): After closing the proper leaks on watch this must be reduced to 0
// The leaks currently come from the event-related code (as in corev1.Event).
threshold := 3

m, err := manager.New(cfg, manager.Options{})
Expect(err).NotTo(HaveOccurred())

_, err = controller.New("new-controller", m, controller.Options{Reconciler: rec})
Expect(err).NotTo(HaveOccurred())

startGoroutines := rt.NumGoroutine()
s := make(chan struct{})
close(s)

Expect(m.Start(s)).NotTo(HaveOccurred())
Expect(rt.NumGoroutine() - startGoroutines).To(BeNumerically("<=", threshold))

close(done)
})
})
})

Expand Down
19 changes: 19 additions & 0 deletions pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"io/ioutil"
"net"
"net/http"
rt "runtime"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/prometheus/client_golang/prometheus"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -748,6 +750,23 @@ var _ = Describe("manger.Manager", func() {
})
})

It("should not leak goroutines when stop", func(done Done) {
// TODO(directxman12): After closing the proper leaks on watch this must be reduced to 0
// The leaks currently come from the event-related code (as in corev1.Event).
threshold := 3

m, err := New(cfg, Options{})
Expect(err).NotTo(HaveOccurred())
startGoruntime := rt.NumGoroutine()

s := make(chan struct{})
close(s)
Expect(m.Start(s)).NotTo(HaveOccurred())

Expect(rt.NumGoroutine() - startGoruntime).To(BeNumerically("<=", threshold))
close(done)
})

It("should provide a function to get the Config", func() {
m, err := New(cfg, Options{})
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 82a78f9

Please sign in to comment.