@@ -1016,126 +1016,78 @@ var _ = Describe("controller", func() {
1016
1016
})
1017
1017
1018
1018
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 () {
1033
1020
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" )
1042
1021
})
1043
1022
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
1046
1025
ctx , cancel := context .WithCancel (context .Background ())
1047
1026
defer cancel ()
1048
1027
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
+ }
1058
1034
1059
- // Act
1060
1035
err := ctrl .Warmup (ctx )
1061
-
1062
- // Assert
1063
1036
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 ())
1066
1041
})
1067
1042
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
1070
1045
ctx , cancel := context .WithCancel (context .Background ())
1071
1046
defer cancel ()
1072
1047
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
+ }
1082
1054
1083
- // Act
1084
1055
err := ctrl .Warmup (ctx )
1056
+ Expect (err ).To (HaveOccurred ())
1057
+ Expect (err .Error ()).To (ContainSubstring ("sync error" ))
1085
1058
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 ())
1090
1062
})
1063
+ })
1091
1064
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 )
1117
1068
})
1118
1069
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
1121
1072
ctx , cancel := context .WithCancel (context .Background ())
1122
1073
defer cancel ()
1123
1074
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
-
1130
1075
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
+ }
1133
1083
1134
- // Act
1135
1084
err := ctrl .Warmup (ctx )
1085
+ Expect (err ).NotTo (HaveOccurred ())
1086
+
1087
+ result := ctrl .DidFinishWarmup (ctx )
1088
+ Expect (result ).To (BeTrue ())
1136
1089
1137
- // Assert
1138
- Expect (err ).To (MatchError (expectedErr ))
1090
+ Expect (isSourceStarted ).To (BeFalse ())
1139
1091
})
1140
1092
})
1141
1093
})
0 commit comments