From 7cb4e3e1624059eb461cf3e59f02e09920c2b9a0 Mon Sep 17 00:00:00 2001 From: Electronic-Waste <2690692950@qq.com> Date: Thu, 19 Sep 2024 03:03:28 +0000 Subject: [PATCH] fix(trial): use the propagated gomega instance to improve debuggability. Signed-off-by: Electronic-Waste <2690692950@qq.com> --- .../trial/trial_controller_test.go | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/pkg/controller.v1beta1/trial/trial_controller_test.go b/pkg/controller.v1beta1/trial/trial_controller_test.go index 8258806f2eb..3a7a3d527fc 100644 --- a/pkg/controller.v1beta1/trial/trial_controller_test.go +++ b/pkg/controller.v1beta1/trial/trial_controller_test.go @@ -301,16 +301,17 @@ func TestReconcileBatchJob(t *testing.T) { // Expect that Trial status is succeeded with "false" status and "metrics unavailable" reason. // Metrics unavailable because GetTrialObservationLog returns "unavailable". - g.Eventually(func() bool { - if err = c.Get(ctx, trialKey, trial); err != nil { - return false - } - return trial.IsMetricsUnavailable() && - len(trial.Status.Observation.Metrics) > 0 && - trial.Status.Observation.Metrics[0].Min == consts.UnavailableMetricValue && - trial.Status.Observation.Metrics[0].Max == consts.UnavailableMetricValue && - trial.Status.Observation.Metrics[0].Latest == consts.UnavailableMetricValue - }, timeout).Should(gomega.BeTrue()) + g.Eventually(func(g gomega.Gomega) { + g.Expect(c.Get(ctx, trialKey, trial)).Should(gomega.Succeed()) + g.Expect(trial.IsMetricsUnavailable()).Should(gomega.BeTrue()) + g.Expect(trial.Status.Observation.Metrics).ShouldNot(gomega.HaveLen(0)) + g.Expect(trial.Status.Observation.Metrics[0]).Should(gomega.BeComparableTo(commonv1beta1.Metric{ + Name: objectiveMetric, + Min: consts.UnavailableMetricValue, + Max: consts.UnavailableMetricValue, + Latest: consts.UnavailableMetricValue, + })) + }, timeout).Should(gomega.Succeed()) // Delete the Trial g.Expect(c.Delete(ctx, trial)).NotTo(gomega.HaveOccurred()) @@ -341,16 +342,17 @@ func TestReconcileBatchJob(t *testing.T) { // Expect that Trial status is succeeded with "false" status and "metrics unavailable" reason. // Metrics unavailable because GetTrialObservationLog returns "unavailable". - g.Eventually(func() bool { - if err = c.Get(ctx, trialKey, trial); err != nil { - return false - } - return trial.IsMetricsUnavailable() && - len(trial.Status.Observation.Metrics) > 0 && - trial.Status.Observation.Metrics[0].Min == consts.UnavailableMetricValue && - trial.Status.Observation.Metrics[0].Max == consts.UnavailableMetricValue && - trial.Status.Observation.Metrics[0].Latest == consts.UnavailableMetricValue - }, timeout).Should(gomega.BeTrue()) + g.Eventually(func(g gomega.Gomega) { + g.Expect(c.Get(ctx, trialKey, trial)).Should(gomega.Succeed()) + g.Expect(trial.IsMetricsUnavailable()).Should(gomega.BeTrue()) + g.Expect(trial.Status.Observation.Metrics).ShouldNot(gomega.HaveLen(0)) + g.Expect(trial.Status.Observation.Metrics[0]).Should(gomega.BeComparableTo(commonv1beta1.Metric{ + Name: objectiveMetric, + Min: consts.UnavailableMetricValue, + Max: consts.UnavailableMetricValue, + Latest: consts.UnavailableMetricValue, + })) + }, timeout).Should(gomega.Succeed()) // Delete the Trial g.Expect(c.Delete(ctx, trial)).NotTo(gomega.HaveOccurred())