Skip to content

Commit e79597d

Browse files
fix some of flaky test in server and biossetting controller
1 parent 1f5ce0e commit e79597d

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

internal/controller/biossettings_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ func checkTransistionToAppliedState(biosSettings *metalv1alpha1.BIOSSettings) {
702702
HaveField("Status.State", metalv1alpha1.BIOSSettingsStateApplied),
703703
))
704704

705-
if biosSettings.Status.State != metalv1alpha1.BIOSSettingsStateApplied {
706-
By("waiting for the server to be turned on")
707-
Eventually(Object(server)).Should(SatisfyAll(
708-
HaveField("Spec.Power", metalv1alpha1.PowerOn),
709-
))
705+
if biosSettings.Status.UpdateSettingState == metalv1alpha1.BIOSSettingUpdateWaitOnServerRebootPowerOn {
706+
// we need to set the spec power as, we need the call to redfish local to be made to apply the settings
707+
Eventually(UpdateStatus(server, func() {
708+
server.Spec.Power = metalv1alpha1.PowerOn
709+
})).Should(Succeed())
710710
Eventually(Object(server)).Should(SatisfyAll(
711711
HaveField("Status.PowerState", metalv1alpha1.ServerOnPowerState),
712712
))

internal/controller/server_controller_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,22 @@ var _ = Describe("Server Controller", func() {
218218
Expect(probeAgent.Start(ctx)).To(Succeed(), "failed to start probe agent")
219219
}()
220220

221-
Eventually(func(g Gomega) {
222-
resp, err := http.Get(fmt.Sprintf("%s/systems/%s", registryURL, server.Spec.SystemUUID))
223-
g.Expect(resp).NotTo(BeNil())
224-
g.Expect(err).NotTo(HaveOccurred())
225-
g.Expect(resp.StatusCode).To(Equal(http.StatusOK))
226-
}).Should(Succeed())
227-
228221
By("Ensuring that the server is set to available and powered off")
229222
Eventually(Object(server)).Should(SatisfyAll(
230-
HaveField("Spec.BootConfigurationRef", BeNil()),
223+
HaveField("Status.State", metalv1alpha1.ServerStateAvailable),
224+
))
225+
// as this is set in the next reconsile cycle after reaching Available state is set,
226+
// its best to check for it later to avoid flakyness
227+
Eventually(Object(server)).Should(SatisfyAll(
231228
HaveField("Status.State", metalv1alpha1.ServerStateAvailable),
232229
HaveField("Status.PowerState", metalv1alpha1.ServerOffPowerState),
233230
HaveField("Status.NetworkInterfaces", Not(BeEmpty())),
234231
))
232+
// as this is set in the next reconsile cycle after power is set,
233+
// its best to check for it later to avoid flakyness
234+
Eventually(Object(server)).Should(SatisfyAll(
235+
HaveField("Spec.BootConfigurationRef", BeNil()),
236+
))
235237

236238
By("Ensuring that the boot configuration has been removed")
237239
Consistently(Get(bootConfig)).Should(Satisfy(apierrors.IsNotFound))
@@ -401,13 +403,6 @@ var _ = Describe("Server Controller", func() {
401403
Expect(probeAgent.Start(ctx)).To(Succeed(), "failed to start probe agent")
402404
}()
403405

404-
Eventually(func(g Gomega) {
405-
resp, err := http.Get(fmt.Sprintf("%s/systems/%s", registryURL, server.Spec.SystemUUID))
406-
g.Expect(resp).NotTo(BeNil())
407-
g.Expect(err).NotTo(HaveOccurred())
408-
g.Expect(resp.StatusCode).To(Equal(http.StatusOK))
409-
}).Should(Succeed())
410-
411406
By("Ensuring that the server is set to available and powered off")
412407
// check that the available state is set first, as that is as part of handling
413408
// the discovery state. The ServerBootConfig deletion happens in a later
@@ -418,7 +413,6 @@ var _ = Describe("Server Controller", func() {
418413
// force calculation of zero capacity string
419414
_ = zeroCapacity.String()
420415
Eventually(Object(server)).Should(SatisfyAll(
421-
HaveField("Spec.BootConfigurationRef", BeNil()),
422416
HaveField("Spec.Power", metalv1alpha1.PowerOff),
423417
HaveField("Status.State", metalv1alpha1.ServerStateAvailable),
424418
HaveField("Status.PowerState", metalv1alpha1.ServerOffPowerState),
@@ -454,6 +448,11 @@ var _ = Describe("Server Controller", func() {
454448
})),
455449
HaveField("Status.Storages", HaveLen(1)),
456450
))
451+
// as this is set in the next reconsile cycle after power is set,
452+
// its best to check for it later to avoid flakyness
453+
Eventually(Object(server)).Should(SatisfyAll(
454+
HaveField("Spec.BootConfigurationRef", BeNil()),
455+
))
457456

458457
By("Ensuring that the boot configuration has been removed")
459458
Consistently(Get(bootConfig)).Should(Satisfy(apierrors.IsNotFound))
@@ -523,6 +522,7 @@ var _ = Describe("Server Controller", func() {
523522
bootConfig.Status.State = metalv1alpha1.ServerBootConfigurationStateReady
524523
})).Should(Succeed())
525524

526-
Eventually(Object(server)).Should(HaveField("Status.State", metalv1alpha1.ServerStateInitial))
525+
// this is large timeout due to the wait time for the DiscoveryTimeout to be hit and then transistioned to Intitial state
526+
Eventually(Object(server)).WithTimeout(5 * time.Second).Should(HaveField("Status.State", metalv1alpha1.ServerStateInitial))
527527
})
528528
})

internal/controller/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func SetupTest() *corev1.Namespace {
222222
PowerPollingTimeout: 200 * time.Millisecond,
223223
BasicAuth: true,
224224
},
225-
DiscoveryTimeout: 500 * time.Millisecond, // Force timeout to be quick for tests
225+
DiscoveryTimeout: 1 * time.Second, // Force timeout to be quick for tests
226226
}).SetupWithManager(k8sManager)).To(Succeed())
227227

228228
Expect((&ServerClaimReconciler{

0 commit comments

Comments
 (0)