@@ -37,6 +37,12 @@ import (
3737 "github.com/banzaicloud/koperator/pkg/scale"
3838)
3939
40+ const (
41+ // Additional test timeout constants for operation controller tests
42+ operationRetryTimeoutDuration = time .Duration (v1alpha1 .DefaultRetryBackOffDurationSec + 10 ) * time .Second // timeout for retry operations
43+ operationExtendedTimeoutDuration = 15 * time .Second // extended timeout for complex operations
44+ )
45+
4046var _ = Describe ("CruiseControlTaskReconciler" , func () {
4147 var (
4248 count uint64 = 0
@@ -114,7 +120,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
114120 return ""
115121 }
116122 return operation .CurrentTaskState ()
117- }, 10 * time . Second , 500 * time . Millisecond ).Should (Equal (v1beta1 .CruiseControlTaskCompleted ))
123+ }, maxReconcileDuration , reconcilePollingPeriod ).Should (Equal (v1beta1 .CruiseControlTaskCompleted ))
118124 })
119125 })
120126 When ("add_broker operation is finished with completedWithError and 30s has not elapsed" , Serial , func () {
@@ -141,13 +147,15 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
141147 return false
142148 }
143149 return operation .CurrentTaskState () == v1beta1 .CruiseControlTaskCompletedWithError && len (operation .Status .FailedTasks ) == 0
144- }, 10 * time . Second , 500 * time . Millisecond ).Should (BeTrue ())
150+ }, maxReconcileDuration , reconcilePollingPeriod ).Should (BeTrue ())
145151 })
146152 })
147153 When ("add_broker operation is finished with completedWithError and 30s has elapsed" , Serial , func () {
148154 JustBeforeEach (func (ctx SpecContext ) {
149155 cruiseControlOperationReconciler .ScaleFactory = mocks .NewMockScaleFactory (getScaleMock5 ())
150156 operation := generateCruiseControlOperation (opName1 , namespace , kafkaCluster .GetName ())
157+ // Explicitly set error policy to retry to ensure retry behavior
158+ operation .Spec .ErrorPolicy = v1alpha1 .ErrorPolicyRetry
151159 err := k8sClient .Create (ctx , & operation )
152160 Expect (err ).NotTo (HaveOccurred ())
153161 operation .Status .CurrentTask = & v1alpha1.CruiseControlTask {
@@ -167,10 +175,17 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
167175 Name : opName1 ,
168176 }, & operation )
169177 if err != nil {
178+ fmt .Printf ("Error getting operation: %v\n " , err )
170179 return false
171180 }
181+
182+ // Debug logging
183+ fmt .Printf ("Operation state: %s, FailedTasks: %d, IsWaitingForRetryExecution: %v, IsReadyForRetryExecution: %v\n " ,
184+ operation .CurrentTaskState (), len (operation .Status .FailedTasks ),
185+ operation .IsWaitingForRetryExecution (), operation .IsReadyForRetryExecution ())
186+
172187 return operation .CurrentTaskState () == v1beta1 .CruiseControlTaskCompleted && len (operation .Status .FailedTasks ) == 1
173- }, 10 * time . Second , 500 * time . Millisecond ).Should (BeTrue ())
188+ }, operationRetryTimeoutDuration , reconcilePollingPeriod ).Should (BeTrue ())
174189 })
175190 })
176191 When ("there is an errored remove_broker and an add_broker operation" , Serial , func () {
@@ -217,7 +232,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
217232 }
218233
219234 return operation2 .CurrentTaskState () == v1beta1 .CruiseControlTaskCompleted
220- }, 10 * time . Second , 500 * time . Millisecond ).Should (BeTrue ())
235+ }, maxReconcileDuration , reconcilePollingPeriod ).Should (BeTrue ())
221236 })
222237 })
223238 When ("there is a new remove_broker and an errored remove_broker operation with pause annotation" , Serial , func () {
@@ -266,7 +281,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
266281 }
267282
268283 return operation1 .Status .RetryCount == 0 && operation2 .CurrentTaskState () == v1beta1 .CruiseControlTaskCompleted
269- }, 10 * time . Second , 500 * time . Millisecond ).Should (BeTrue ())
284+ }, maxReconcileDuration , reconcilePollingPeriod ).Should (BeTrue ())
270285 })
271286 })
272287 When ("there is a new remove_broker and an errored remove_broker operation with ignore ErrorPolicy" , Serial , func () {
@@ -316,7 +331,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
316331 }
317332
318333 return operation1 .Status .RetryCount == 0 && operation2 .CurrentTaskState () == v1beta1 .CruiseControlTaskCompleted
319- }, 10 * time . Second , 500 * time . Millisecond ).Should (BeTrue ())
334+ }, maxReconcileDuration , reconcilePollingPeriod ).Should (BeTrue ())
320335 })
321336 })
322337 When ("there is an errored remove_disks and a rebalance disks operation for the same broker" , Serial , func () {
@@ -370,7 +385,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
370385
371386 return rebalanceOp .CurrentTaskState () == v1beta1 .CruiseControlTaskCompleted &&
372387 removeDisksOp .GetLabels ()[v1alpha1 .PauseLabel ] == v1alpha1 .True
373- }, 10 * time . Second , 500 * time . Millisecond ).Should (BeTrue ())
388+ }, maxReconcileDuration , reconcilePollingPeriod ).Should (BeTrue ())
374389 })
375390 })
376391 When ("Cruise Control makes the Status operation async" , Serial , func () {
@@ -398,7 +413,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
398413 return ""
399414 }
400415 return operation .CurrentTaskState ()
401- }, 15 * time . Second , 500 * time . Millisecond ).Should (Equal (v1beta1 .CruiseControlTaskCompleted ))
416+ }, operationExtendedTimeoutDuration , reconcilePollingPeriod ).Should (Equal (v1beta1 .CruiseControlTaskCompleted ))
402417 })
403418 })
404419})
0 commit comments