Skip to content

Commit b1caf52

Browse files
committed
[BUILD] Make e2e tests output less verbose and fix flaky NodePort unit-tests
1 parent 1e6cd53 commit b1caf52

File tree

10 files changed

+165
-174
lines changed

10 files changed

+165
-174
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ all: test manager ## Run 'test' and 'manager' targets.
5353
.PHONY: check
5454
check: test lint ## Run tests and linters
5555

56+
.PHONY: clean
57+
clean: ## Clean build artifacts and test binaries
58+
@echo "Cleaning build artifacts..."
59+
@if [ -d "bin" ]; then \
60+
chmod -R u+w bin/ 2>/dev/null || true; \
61+
rm -rf bin/; \
62+
fi
63+
@rm -f cover.out
64+
@rm -f manager_image_patch.yaml
65+
5666
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION} ## Symlink golangi-lint-<version> into versionless golangci-lint.
5767
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
5868
bin/golangci-lint-${GOLANGCI_VERSION}: ## Download versioned golangci-lint.
@@ -95,7 +105,6 @@ install-kustomize: ## Install kustomize.
95105
test: generate fmt vet bin/setup-envtest
96106
cd api && go test ./...
97107
KUBEBUILDER_ASSETS=$$($(BIN_DIR)/setup-envtest --print path --bin-dir $(BIN_DIR) use $(ENVTEST_K8S_VERSION)) \
98-
GINKGO_FLAKE_ATTEMPTS=3 \
99108
go test ./... \
100109
-coverprofile cover.out \
101110
-v \

controllers/tests/common_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ func createMinimalKafkaClusterCR(name, namespace string) *banzaicloudv1beta1.Kaf
132132
}
133133

134134
func waitForClusterRunningState(ctx context.Context, kafkaCluster *banzaicloudv1beta1.KafkaCluster, namespace string) {
135+
waitForClusterRunningStateWithTimeout(ctx, kafkaCluster, namespace, 240*time.Second)
136+
}
137+
138+
func waitForClusterRunningStateWithTimeout(ctx context.Context, kafkaCluster *banzaicloudv1beta1.KafkaCluster, namespace string, timeout time.Duration) {
135139
ctx, cancel := context.WithCancel(ctx)
136140
defer cancel()
137141

@@ -161,7 +165,7 @@ func waitForClusterRunningState(ctx context.Context, kafkaCluster *banzaicloudv1
161165
}
162166
}
163167
}()
164-
Eventually(ch, 240*time.Second, 50*time.Millisecond).Should(Receive())
168+
Eventually(ch, timeout, 50*time.Millisecond).Should(Receive())
165169
}
166170

167171
func getMockedKafkaClientForCluster(kafkaCluster *banzaicloudv1beta1.KafkaCluster) (kafkaclient.KafkaClient, func()) {

controllers/tests/cruisecontroloperation_controller_test.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4046
var _ = 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
})

controllers/tests/cruisecontroltask_controller_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ import (
3737
"github.com/banzaicloud/koperator/pkg/util"
3838
)
3939

40+
const (
41+
// Additional test timeout constants for task controller tests
42+
taskRetryTimeoutDuration = time.Duration(v1alpha1.DefaultRetryBackOffDurationSec+10) * time.Second // timeout for retry operations
43+
taskExtendedTimeoutDuration = 15 * time.Second // extended timeout for complex operations
44+
)
45+
4046
var _ = Describe("CruiseControlTaskReconciler", func() {
4147
var (
4248
count uint64 = 0
@@ -65,6 +71,11 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
6571
kafkaCluster = createMinimalKafkaClusterCR(kafkaClusterCRName, namespace)
6672
})
6773

74+
JustAfterEach(func(ctx SpecContext) {
75+
// Reset the ScaleFactory to prevent interference with other tests
76+
kafkaClusterCCReconciler.ScaleFactory = mocks.NewNoopScaleFactory()
77+
})
78+
6879
JustBeforeEach(func(ctx context.Context) {
6980
By("creating namespace " + namespace)
7081
err := k8sClient.Create(ctx, namespaceObj)
@@ -142,7 +153,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
142153
volumeState.CruiseControlVolumeState == v1beta1.GracefulDiskRebalanceScheduled &&
143154
operation.CurrentTask() != nil && operation.CurrentTask().Parameters["rebalance_disk"] == trueStr
144155

145-
}, 15*time.Second, 500*time.Millisecond).Should(BeTrue())
156+
}, taskExtendedTimeoutDuration, reconcilePollingPeriod).Should(BeTrue())
146157
})
147158
})
148159
When("new storage is added but there is a not JBOD capacityConfig for that", Serial, func() {
@@ -222,7 +233,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
222233
volumeState.CruiseControlVolumeState == v1beta1.GracefulDiskRebalanceScheduled &&
223234
operation.CurrentTask() != nil && operation.CurrentTask().Parameters["rebalance_disk"] != trueStr
224235

225-
}, 15*time.Second, 500*time.Millisecond).Should(BeTrue())
236+
}, taskExtendedTimeoutDuration, reconcilePollingPeriod).Should(BeTrue())
226237
})
227238
})
228239
When("new storage is added and one broker is JBOD and another is not JBOD", Serial, func() {
@@ -307,7 +318,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
307318
operation.CurrentTaskOperation() == v1alpha1.OperationRebalance &&
308319
volumeState.CruiseControlVolumeState == v1beta1.GracefulDiskRebalanceScheduled &&
309320
operation.CurrentTask() != nil && operation.CurrentTask().Parameters["rebalance_disk"] != trueStr
310-
}, 15*time.Second, 500*time.Millisecond).Should(BeTrue())
321+
}, taskExtendedTimeoutDuration, reconcilePollingPeriod).Should(BeTrue())
311322
})
312323
})
313324
When("new broker is added", Serial, func() {
@@ -350,7 +361,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
350361

351362
}
352363
return false
353-
}, 10*time.Second, 500*time.Millisecond).Should(BeTrue())
364+
}, maxReconcileDuration, reconcilePollingPeriod).Should(BeTrue())
354365
})
355366
When("created CruiseControlOperation state is inExecution", Serial, func() {
356367
It("kafkaCluster gracefulActionState should be GracefulUpscaleRunning", func(ctx SpecContext) {
@@ -393,7 +404,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
393404
operation.CurrentTaskOperation() == v1alpha1.OperationAddBroker && actionState.CruiseControlState == v1beta1.GracefulUpscaleRunning
394405
}
395406
return false
396-
}, 10*time.Second, 500*time.Millisecond).Should(BeTrue())
407+
}, maxReconcileDuration, reconcilePollingPeriod).Should(BeTrue())
397408
})
398409
})
399410

@@ -442,7 +453,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
442453
return actionState.CruiseControlOperationReference.Name == operation.Name && operation.CurrentTaskOperation() == v1alpha1.OperationRemoveBroker && actionState.CruiseControlState == v1beta1.GracefulDownscaleScheduled
443454
}
444455
return false
445-
}, 15*time.Second, 500*time.Millisecond).Should(BeTrue())
456+
}, taskExtendedTimeoutDuration, reconcilePollingPeriod).Should(BeTrue())
446457
})
447458
})
448459
})

0 commit comments

Comments
 (0)