Skip to content

Commit

Permalink
test(trial): debug by converting Push MC UTs to StdOut MC UTs.
Browse files Browse the repository at this point in the history
Signed-off-by: Electronic-Waste <[email protected]>
  • Loading branch information
Electronic-Waste committed Sep 3, 2024
1 parent f780fa2 commit f04367b
Showing 1 changed file with 69 additions and 69 deletions.
138 changes: 69 additions & 69 deletions pkg/controller.v1beta1/trial/trial_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f04367b

Please sign in to comment.