@@ -21,6 +21,7 @@ import (
2121 "errors"
2222 "fmt"
2323 "sync"
24+ "sync/atomic"
2425 "time"
2526
2627 "github.com/go-logr/logr"
@@ -1062,32 +1063,38 @@ var _ = Describe("controller", func() {
10621063 })
10631064 })
10641065
1065- Describe ("Warmup without warmup enabled " , func () {
1066+ Describe ("Warmup with warmup disabled " , func () {
10661067 JustBeforeEach (func () {
10671068 ctrl .NeedWarmup = ptr .To (false )
10681069 })
10691070
1070- It ("should not start sources if warmup is disabled." , func () {
1071+ It ("should not start sources when Warmup is called if warmup is disabled but start it when Start is called ." , func () {
10711072 // Setup controller with sources that complete successfully
10721073 ctx , cancel := context .WithCancel (context .Background ())
10731074 defer cancel ()
10741075
10751076 ctrl .CacheSyncTimeout = time .Second
1076- isSourceStarted := false
1077+ var isSourceStarted atomic.Bool
1078+ isSourceStarted .Store (false )
10771079 ctrl .startWatches = []source.TypedSource [reconcile.Request ]{
10781080 source .Func (func (ctx context.Context , _ workqueue.TypedRateLimitingInterface [reconcile.Request ]) error {
1079- isSourceStarted = true
1081+ isSourceStarted . Store ( true )
10801082 return nil
10811083 }),
10821084 }
10831085
1086+ By ("Calling Warmup when NeedWarmup is false" )
10841087 err := ctrl .Warmup (ctx )
10851088 Expect (err ).NotTo (HaveOccurred ())
1089+ Expect (isSourceStarted .Load ()).To (BeFalse ())
10861090
1087- result := ctrl .DidFinishWarmup (ctx )
1088- Expect (result ).To (BeTrue ())
1089-
1090- Expect (isSourceStarted ).To (BeFalse ())
1091+ By ("Calling Start when NeedWarmup is false" )
1092+ // Now call Start
1093+ go func () {
1094+ defer GinkgoRecover ()
1095+ Expect (ctrl .Start (ctx )).To (Succeed ())
1096+ }()
1097+ Eventually (func () bool { return isSourceStarted .Load () }).Should (BeTrue ())
10911098 })
10921099 })
10931100})
0 commit comments