From f04367bb97d537865f76a7fce465ef0204434c92 Mon Sep 17 00:00:00 2001 From: Electronic-Waste <2690692950@qq.com> Date: Tue, 3 Sep 2024 05:22:55 +0000 Subject: [PATCH] test(trial): debug by converting Push MC UTs to StdOut MC UTs. Signed-off-by: Electronic-Waste <2690692950@qq.com> --- .../trial/trial_controller_test.go | 138 +++++++++--------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/pkg/controller.v1beta1/trial/trial_controller_test.go b/pkg/controller.v1beta1/trial/trial_controller_test.go index f4c8e770a7d..b1e1f44e596 100644 --- a/pkg/controller.v1beta1/trial/trial_controller_test.go +++ b/pkg/controller.v1beta1/trial/trial_controller_test.go @@ -324,75 +324,75 @@ func TestReconcileBatchJob(t *testing.T) { }, timeout).Should(gomega.BeTrue()) }) - // t.Run(`Trail with "Complete" BatchJob and Unavailable metrics(Push MC).`, func(t *testing.T) { - // g := gomega.NewGomegaWithT(t) - // gomock.InOrder( - // mockManagerClient.EXPECT().GetTrialObservationLog(gomock.Any()).Return(observationLogUnavailable, nil).MinTimes(1), - // mockManagerClient.EXPECT().ReportTrialObservationLog(gomock.Any(), gomock.Any()).Return(nil, nil).MinTimes(1), - // mockManagerClient.EXPECT().DeleteTrialObservationLog(gomock.Any()).Return(nil, nil), - // ) - // // Create the Trial with Push MC - // trial := newFakeTrialBatchJob(commonv1beta1.PushCollector, "test-unavailable-push") - // trialKey := types.NamespacedName{Name: "test-unavailable-push", Namespace: namespace} - // g.Expect(c.Create(ctx, trial)).NotTo(gomega.HaveOccurred()) - - // // 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()) - - // // Delete the Trial - // g.Expect(c.Delete(ctx, trial)).NotTo(gomega.HaveOccurred()) - - // // Expect that Trial is deleted - // g.Eventually(func() bool { - // return errors.IsNotFound(c.Get(ctx, trialKey, &trialsv1beta1.Trial{})) - // }, timeout).Should(gomega.BeTrue()) - // }) - - // t.Run(`Trail with "Complete" BatchJob and Unavailable metrics(Push MC, failed once).`, func(t *testing.T) { - // g := gomega.NewGomegaWithT(t) - // gomock.InOrder( - // mockManagerClient.EXPECT().GetTrialObservationLog(gomock.Any()).Return(observationLogUnavailable, nil).MinTimes(1), - // mockManagerClient.EXPECT().ReportTrialObservationLog(gomock.Any(), gomock.Any()).Return(nil, errReportMetricsFailed).MinTimes(1), - // mockManagerClient.EXPECT().GetTrialObservationLog(gomock.Any()).Return(observationLogUnavailable, nil).MinTimes(1), - // mockManagerClient.EXPECT().ReportTrialObservationLog(gomock.Any(), gomock.Any()).Return(nil, nil).MinTimes(1), - // mockManagerClient.EXPECT().DeleteTrialObservationLog(gomock.Any()).Return(nil, nil), - // ) - // // Create the Trial with Push MC - // trial := newFakeTrialBatchJob(commonv1beta1.StdOutCollector, "test-unavailable-push-failed-once") - // trialKey := types.NamespacedName{Name: "test-unavailable-push-failed-once", Namespace: namespace} - // g.Expect(c.Create(ctx, trial)).NotTo(gomega.HaveOccurred()) - - // // 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()) - - // // Delete the Trial - // g.Expect(c.Delete(ctx, trial)).NotTo(gomega.HaveOccurred()) - - // // Expect that Trial is deleted - // g.Eventually(func() bool { - // return errors.IsNotFound(c.Get(ctx, trialKey, &trialsv1beta1.Trial{})) - // }, timeout).Should(gomega.BeTrue()) - // }) + t.Run(`Trail with "Complete" BatchJob and Unavailable metrics(Push MC).`, func(t *testing.T) { + g := gomega.NewGomegaWithT(t) + gomock.InOrder( + mockManagerClient.EXPECT().GetTrialObservationLog(gomock.Any()).Return(observationLogUnavailable, nil).MinTimes(1), + // mockManagerClient.EXPECT().ReportTrialObservationLog(gomock.Any(), gomock.Any()).Return(nil, nil).MinTimes(1), + mockManagerClient.EXPECT().DeleteTrialObservationLog(gomock.Any()).Return(nil, nil), + ) + // Create the Trial with Push MC + trial := newFakeTrialBatchJob(commonv1beta1.StdOutCollector, "test-unavailable-push") + trialKey := types.NamespacedName{Name: "test-unavailable-push", Namespace: namespace} + g.Expect(c.Create(ctx, trial)).NotTo(gomega.HaveOccurred()) + + // 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()) + + // Delete the Trial + g.Expect(c.Delete(ctx, trial)).NotTo(gomega.HaveOccurred()) + + // Expect that Trial is deleted + g.Eventually(func() bool { + return errors.IsNotFound(c.Get(ctx, trialKey, &trialsv1beta1.Trial{})) + }, timeout).Should(gomega.BeTrue()) + }) + + t.Run(`Trail with "Complete" BatchJob and Unavailable metrics(Push MC, failed once).`, func(t *testing.T) { + g := gomega.NewGomegaWithT(t) + gomock.InOrder( + mockManagerClient.EXPECT().GetTrialObservationLog(gomock.Any()).Return(observationLogUnavailable, nil).MinTimes(1), + // mockManagerClient.EXPECT().ReportTrialObservationLog(gomock.Any(), gomock.Any()).Return(nil, errReportMetricsFailed).MinTimes(1), + // mockManagerClient.EXPECT().GetTrialObservationLog(gomock.Any()).Return(observationLogUnavailable, nil).MinTimes(1), + // mockManagerClient.EXPECT().ReportTrialObservationLog(gomock.Any(), gomock.Any()).Return(nil, nil).MinTimes(1), + mockManagerClient.EXPECT().DeleteTrialObservationLog(gomock.Any()).Return(nil, nil), + ) + // Create the Trial with Push MC + trial := newFakeTrialBatchJob(commonv1beta1.StdOutCollector, "test-unavailable-push-failed-once") + trialKey := types.NamespacedName{Name: "test-unavailable-push-failed-once", Namespace: namespace} + g.Expect(c.Create(ctx, trial)).NotTo(gomega.HaveOccurred()) + + // 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()) + + // Delete the Trial + g.Expect(c.Delete(ctx, trial)).NotTo(gomega.HaveOccurred()) + + // Expect that Trial is deleted + g.Eventually(func() bool { + return errors.IsNotFound(c.Get(ctx, trialKey, &trialsv1beta1.Trial{})) + }, timeout).Should(gomega.BeTrue()) + }) t.Run("Update status for empty Trial", func(t *testing.T) { g := gomega.NewGomegaWithT(t)