@@ -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,54 @@ 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
+ var log struct {
1052
+ sync.Mutex
1053
+ messages []string
1054
+ }
1055
+ options .Logger = funcr .NewJSON (func (object string ) {
1056
+ log .Lock ()
1057
+ log .messages = append (log .messages , object )
1058
+ log .Unlock ()
1059
+ }, funcr.Options {})
1060
+
1061
+ m , err := New (cfg , options )
1062
+ Expect (err ).NotTo (HaveOccurred ())
1063
+ for _ , cb := range callbacks {
1064
+ cb (m )
1065
+ }
1066
+
1067
+ // Runnables may return ctx.Err() as shown in some [context.Context] examples.
1068
+ started := make (chan struct {})
1069
+ Expect (m .Add (RunnableFunc (func (ctx context.Context ) error {
1070
+ close (started )
1071
+ <- ctx .Done ()
1072
+ return ctx .Err ()
1073
+ }))).To (Succeed ())
1074
+
1075
+ stopped := make (chan error )
1076
+ ctx , cancel := context .WithCancel (context .Background ())
1077
+ go func () {
1078
+ stopped <- m .Start (ctx )
1079
+ }()
1080
+
1081
+ // Wait for runnables to start, signal the manager, and wait for it.
1082
+ <- started
1083
+ cancel ()
1084
+ Expect (<- stopped ).To (Succeed ())
1085
+
1086
+ // TODO: Diagnose why LeaderElection races after Start() returns.
1087
+ if options .LeaderElection {
1088
+ time .Sleep (time .Second )
1089
+ }
1090
+
1091
+ Expect (log .messages ).To (Not (ContainElement (
1092
+ ContainSubstring (context .Canceled .Error ()),
1093
+ )))
1094
+ })
1095
+
1047
1096
It ("should return both runnables and stop errors when both error" , func () {
1048
1097
m , err := New (cfg , options )
1049
1098
Expect (err ).NotTo (HaveOccurred ())
0 commit comments