Skip to content

Commit

Permalink
add test that uses NewCancelRunnable
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Feb 14, 2023
1 parent a6dc090 commit bffdb89
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
ctrlmetrics "sigs.k8s.io/controller-runtime/pkg/internal/controller/metrics"
"sigs.k8s.io/controller-runtime/pkg/internal/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
Expand Down Expand Up @@ -345,6 +346,30 @@ var _ = Describe("controller", func() {
Expect(err.Error()).To(Equal("can not restart a stopped controller, you should create a new one"))
})

It("should be possible to cancel the controller using NewCancelRunnable", func() {
stoppedChan := make(chan struct{})
cancellableController, cancel := manager.NewCancelRunnable(ctrl)

go func() {
defer close(stoppedChan)
defer GinkgoRecover()
Expect(cancellableController.Start(context.Background())).NotTo(HaveOccurred())
}()

var started bool
for !started {
func() {
ctrl.mu.Lock()
defer ctrl.mu.Unlock()
started = ctrl.Started
}()
}

cancel()

<-stoppedChan
Eventually(ctrl.Stopped).Should(BeTrue())
})
})

Describe("Processing queue items from a Controller", func() {
Expand Down

0 comments on commit bffdb89

Please sign in to comment.