@@ -30,6 +30,7 @@ import (
30
30
"time"
31
31
32
32
"github.com/go-logr/logr"
33
+ "github.com/go-logr/logr/funcr"
33
34
. "github.com/onsi/ginkgo/v2"
34
35
. "github.com/onsi/gomega"
35
36
"github.com/prometheus/client_golang/prometheus"
@@ -1044,6 +1045,44 @@ var _ = Describe("manger.Manager", func() {
1044
1045
}))).NotTo (Succeed ())
1045
1046
})
1046
1047
1048
+ It ("should not return runnables context.Canceled errors" , func () {
1049
+ Expect (options .Logger ).To (BeZero (), "this test overrides Logger" )
1050
+
1051
+ logs := []string {}
1052
+ options .Logger = funcr .NewJSON (func (object string ) {
1053
+ logs = append (logs , object )
1054
+ }, funcr.Options {})
1055
+
1056
+ m , err := New (cfg , options )
1057
+ Expect (err ).NotTo (HaveOccurred ())
1058
+ for _ , cb := range callbacks {
1059
+ cb (m )
1060
+ }
1061
+
1062
+ // Runnables may return ctx.Err() as shown in some [context.Context] examples.
1063
+ started := make (chan struct {})
1064
+ Expect (m .Add (RunnableFunc (func (ctx context.Context ) error {
1065
+ close (started )
1066
+ <- ctx .Done ()
1067
+ return ctx .Err ()
1068
+ }))).To (Succeed ())
1069
+
1070
+ stopped := make (chan error )
1071
+ ctx , cancel := context .WithCancel (context .Background ())
1072
+ go func () {
1073
+ stopped <- m .Start (ctx )
1074
+ }()
1075
+
1076
+ // Wait for runnables to start, signal the manager, and wait for it.
1077
+ <- started
1078
+ cancel ()
1079
+ Expect (<- stopped ).To (Succeed ())
1080
+
1081
+ Expect (logs ).To (Not (ContainElement (
1082
+ ContainSubstring (context .Canceled .Error ()),
1083
+ )))
1084
+ })
1085
+
1047
1086
It ("should return both runnables and stop errors when both error" , func () {
1048
1087
m , err := New (cfg , options )
1049
1088
Expect (err ).NotTo (HaveOccurred ())
0 commit comments