@@ -1016,126 +1016,78 @@ var _ = Describe("controller", func() {
10161016 })
10171017
10181018 Describe ("Warmup" , func () {
1019- It ("should start event sources when NeedWarmup is true" , func () {
1020- // Setup
1021- ctx , cancel := context .WithCancel (context .Background ())
1022- defer cancel ()
1023-
1024- // Create a mock source that we can verify was started
1025- sourceStarted := false
1026- mockSource := source .Func (func (ctx context.Context , queue workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1027- sourceStarted = true
1028- return nil
1029- })
1030-
1031- ctrl .CacheSyncTimeout = time .Second
1032- ctrl .startWatches = []source.TypedSource [reconcile.Request ]{mockSource }
1019+ JustBeforeEach (func () {
10331020 ctrl .NeedWarmup = ptr .To (true )
1034-
1035- // Act
1036- err := ctrl .Warmup (ctx )
1037-
1038- // Assert
1039- Expect (err ).NotTo (HaveOccurred ())
1040- Expect (sourceStarted ).To (BeTrue (), "Event source should have been started" )
1041- Expect (ctrl .didStartEventSources .Load ()).To (BeTrue (), "didStartEventSources flag should be set" )
10421021 })
10431022
1044- It ("should not start event sources when NeedWarmup is false " , func () {
1045- // Setup
1023+ It ("should track warmup status correctly with successful sync " , func () {
1024+ // Setup controller with sources that complete successfully
10461025 ctx , cancel := context .WithCancel (context .Background ())
10471026 defer cancel ()
10481027
1049- // Create a mock source that should not be started
1050- sourceStarted := false
1051- mockSource := source .Func (func (ctx context.Context , queue workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1052- sourceStarted = true
1053- return nil
1054- })
1055-
1056- ctrl .startWatches = []source.TypedSource [reconcile.Request ]{mockSource }
1057- ctrl .NeedWarmup = ptr .To (false )
1028+ ctrl .CacheSyncTimeout = time .Second
1029+ ctrl .startWatches = []source.TypedSource [reconcile.Request ]{
1030+ source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1031+ return nil
1032+ }),
1033+ }
10581034
1059- // Act
10601035 err := ctrl .Warmup (ctx )
1061-
1062- // Assert
10631036 Expect (err ).NotTo (HaveOccurred ())
1064- Expect (sourceStarted ).To (BeFalse (), "Event source should not have been started" )
1065- Expect (ctrl .didStartEventSources .Load ()).To (BeFalse (), "didStartEventSources flag should not be set" )
1037+
1038+ // Verify DidFinishWarmup returns true for successful sync
1039+ result := ctrl .DidFinishWarmup (ctx )
1040+ Expect (result ).To (BeTrue ())
10661041 })
10671042
1068- It ("should not start event sources when NeedWarmup is nil " , func () {
1069- // Setup
1043+ It ("should track warmup status correctly with unsuccessful sync " , func () {
1044+ // Setup controller with sources that complete with error
10701045 ctx , cancel := context .WithCancel (context .Background ())
10711046 defer cancel ()
10721047
1073- // Create a mock source that should not be started
1074- sourceStarted := false
1075- mockSource := source .Func (func (ctx context.Context , queue workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1076- sourceStarted = true
1077- return nil
1078- })
1079-
1080- ctrl .startWatches = []source.TypedSource [reconcile.Request ]{mockSource }
1081- ctrl .NeedWarmup = nil
1048+ ctrl .CacheSyncTimeout = time .Second
1049+ ctrl .startWatches = []source.TypedSource [reconcile.Request ]{
1050+ source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1051+ return errors .New ("sync error" )
1052+ }),
1053+ }
10821054
1083- // Act
10841055 err := ctrl .Warmup (ctx )
1056+ Expect (err ).To (HaveOccurred ())
1057+ Expect (err .Error ()).To (ContainSubstring ("sync error" ))
10851058
1086- // Assert
1087- Expect (err ).NotTo (HaveOccurred ())
1088- Expect (sourceStarted ).To (BeFalse (), "Event source should not have been started" )
1089- Expect (ctrl .didStartEventSources .Load ()).To (BeFalse (), "didStartEventSources flag should not be set" )
1059+ // Verify DidFinishWarmup returns false for unsuccessful sync
1060+ result := ctrl .DidFinishWarmup (ctx )
1061+ Expect (result ).To (BeFalse ())
10901062 })
1063+ })
10911064
1092- It ("should not start event sources twice when called multiple times" , func () {
1093- // Setup
1094- ctx , cancel := context .WithCancel (context .Background ())
1095- defer cancel ()
1096-
1097- // Create a mock source that counts how many times it's started
1098- startCount := 0
1099- mockSource := source .Func (func (ctx context.Context , queue workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1100- startCount ++
1101- return nil
1102- })
1103-
1104- ctrl .CacheSyncTimeout = time .Second
1105- ctrl .startWatches = []source.TypedSource [reconcile.Request ]{mockSource }
1106- ctrl .NeedWarmup = ptr .To (true )
1107-
1108- // Act
1109- err1 := ctrl .Warmup (ctx )
1110- err2 := ctrl .Warmup (ctx )
1111-
1112- // Assert
1113- Expect (err1 ).NotTo (HaveOccurred ())
1114- Expect (err2 ).NotTo (HaveOccurred ())
1115- Expect (startCount ).To (Equal (1 ), "Event source should have been started only once" )
1116- Expect (ctrl .didStartEventSources .Load ()).To (BeTrue (), "didStartEventSources flag should be set" )
1065+ Describe ("Warmup without warmup enabled" , func () {
1066+ JustBeforeEach (func () {
1067+ ctrl .NeedWarmup = ptr .To (false )
11171068 })
11181069
1119- It ("should propagate errors from event sources " , func () {
1120- // Setup
1070+ It ("should not start sources if warmup is disabled. " , func () {
1071+ // Setup controller with sources that complete successfully
11211072 ctx , cancel := context .WithCancel (context .Background ())
11221073 defer cancel ()
11231074
1124- // Create a mock source that returns an error
1125- expectedErr := errors .New ("test error" )
1126- mockSource := source .Func (func (ctx context.Context , queue workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1127- return expectedErr
1128- })
1129-
11301075 ctrl .CacheSyncTimeout = time .Second
1131- ctrl .startWatches = []source.TypedSource [reconcile.Request ]{mockSource }
1132- ctrl .NeedWarmup = ptr .To (true )
1076+ isSourceStarted := false
1077+ ctrl .startWatches = []source.TypedSource [reconcile.Request ]{
1078+ source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1079+ isSourceStarted = true
1080+ return nil
1081+ }),
1082+ }
11331083
1134- // Act
11351084 err := ctrl .Warmup (ctx )
1085+ Expect (err ).NotTo (HaveOccurred ())
1086+
1087+ result := ctrl .DidFinishWarmup (ctx )
1088+ Expect (result ).To (BeTrue ())
11361089
1137- // Assert
1138- Expect (err ).To (MatchError (expectedErr ))
1090+ Expect (isSourceStarted ).To (BeFalse ())
11391091 })
11401092 })
11411093})
0 commit comments