Skip to content

Commit b7eea92

Browse files
fix(test): update job status first in failed test.
Signed-off-by: Electronic-Waste <[email protected]>
1 parent e1f4ce8 commit b7eea92

File tree

1 file changed

+31
-42
lines changed

1 file changed

+31
-42
lines changed

pkg/controller.v1beta1/trial/trial_controller_test.go

+31-42
Original file line numberDiff line numberDiff line change
@@ -326,55 +326,44 @@ func TestReconcileBatchJob(t *testing.T) {
326326
g := gomega.NewGomegaWithT(t)
327327
mockManagerClient.EXPECT().DeleteTrialObservationLog(gomock.Any()).Return(nil, nil)
328328

329-
trial := newFakeTrialBatchJob(commonv1beta1.StdOutCollector, "test-failed-batch-job")
330-
trialKey := types.NamespacedName{Name: "test-failed-batch-job", Namespace: namespace}
329+
// Manually update BatchJob status to failed
331330
batchJob := &batchv1.Job{}
331+
batchJobFailedMessage := "BatchJob completed test message"
332+
batchJobFailedReason := "BatchJob completed test reason"
333+
g.Expect(c.Get(ctx, batchJobKey, batchJob)).NotTo(gomega.HaveOccurred())
334+
g.Expect(c.Get(ctx, batchJobKey, batchJob)).Should(gomega.Succeed())
335+
batchJob.Status = batchv1.JobStatus{
336+
Conditions: []batchv1.JobCondition{
337+
{
338+
Type: batchv1.JobFailureTarget,
339+
Status: corev1.ConditionTrue,
340+
Message: batchJobFailedMessage,
341+
Reason: batchJobFailedReason,
342+
},
343+
{
344+
Type: batchv1.JobFailed,
345+
Status: corev1.ConditionTrue,
346+
Message: batchJobFailedMessage,
347+
Reason: batchJobFailedReason,
348+
},
349+
{
350+
Type: batchv1.JobSuccessCriteriaMet,
351+
Status: corev1.ConditionFalse,
352+
Message: batchJobFailedMessage,
353+
Reason: batchJobFailedReason,
354+
},
355+
},
356+
StartTime: &metav1.Time{Time: startTime},
357+
}
358+
g.Expect(c.Status().Update(ctx, batchJob)).Should(gomega.Succeed())
332359

333360
// Create the Trial with StdOut MC
361+
trial := newFakeTrialBatchJob(commonv1beta1.StdOutCollector, "test-failed-batch-job")
362+
trialKey := types.NamespacedName{Name: "test-failed-batch-job", Namespace: namespace}
334363
g.Expect(c.Create(ctx, trial)).NotTo(gomega.HaveOccurred())
335364

336-
// Expect that BatchJob with appropriate name is created
337-
g.Eventually(func(g gomega.Gomega) {
338-
g.Expect(c.Get(ctx, batchJobKey, batchJob)).Should(gomega.Succeed())
339-
}, timeout).Should(gomega.Succeed())
340-
341-
// Expect that Trial status is running
342-
g.Eventually(func(g gomega.Gomega) {
343-
g.Expect(c.Get(ctx, trialKey, trial)).Should(gomega.Succeed())
344-
t.Log(*trial)
345-
g.Expect(trial.IsRunning()).Should(gomega.BeTrue())
346-
}, timeout).Should(gomega.Succeed())
347-
348-
// Manually update BatchJob status to failed
349365
// Expect that Trial status is failed
350-
batchJobFailedMessage := "BatchJob completed test message"
351-
batchJobFailedReason := "BatchJob completed test reason"
352366
g.Eventually(func(g gomega.Gomega) {
353-
g.Expect(c.Get(ctx, batchJobKey, batchJob)).Should(gomega.Succeed())
354-
batchJob.Status = batchv1.JobStatus{
355-
Conditions: []batchv1.JobCondition{
356-
{
357-
Type: batchv1.JobFailureTarget,
358-
Status: corev1.ConditionTrue,
359-
Message: batchJobFailedMessage,
360-
Reason: batchJobFailedReason,
361-
},
362-
{
363-
Type: batchv1.JobFailed,
364-
Status: corev1.ConditionTrue,
365-
Message: batchJobFailedMessage,
366-
Reason: batchJobFailedReason,
367-
},
368-
{
369-
Type: batchv1.JobSuccessCriteriaMet,
370-
Status: corev1.ConditionFalse,
371-
Message: batchJobFailedMessage,
372-
Reason: batchJobFailedReason,
373-
},
374-
},
375-
StartTime: &metav1.Time{Time: startTime},
376-
}
377-
g.Expect(c.Status().Update(ctx, batchJob)).Should(gomega.Succeed())
378367
g.Expect(c.Get(ctx, trialKey, trial)).Should(gomega.Succeed())
379368
g.Expect(trial.IsFailed()).Should(gomega.BeTrue())
380369
}, timeout).Should(gomega.Succeed())

0 commit comments

Comments
 (0)