Skip to content

Commit 162a333

Browse files
fix(test): create a new Job after the failed job.
Signed-off-by: Electronic-Waste <[email protected]>
1 parent d90720d commit 162a333

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pkg/controller.v1beta1/trial/trial_controller_test.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,16 @@ func TestReconcileBatchJob(t *testing.T) {
228228
g.Expect(trial.IsFailed()).Should(gomega.BeTrue())
229229
}, timeout).Should(gomega.Succeed())
230230

231-
// Delete the Trial
231+
// Delete the Trial and Job
232232
g.Expect(c.Delete(ctx, trial)).NotTo(gomega.HaveOccurred())
233+
g.Expect(c.Delete(ctx, batchJob)).NotTo(gomega.HaveOccurred())
233234

234235
// Expect that Trial is deleted
235236
// BatchJob can't be deleted because GC doesn't work in envtest and BatchJob stuck in termination phase.
236237
// Ref: https://book.kubebuilder.io/reference/testing/envtest.html#testing-considerations.
237238
g.Eventually(func(g gomega.Gomega) {
238239
g.Expect(errors.IsNotFound(c.Get(ctx, trialKey, &trialsv1beta1.Trial{}))).Should(gomega.BeTrue())
240+
g.Expect(errors.IsNotFound(c.Get(ctx, batchJobKey, &batchv1.Job{}))).Should(gomega.BeTrue())
239241
}, timeout).Should(gomega.Succeed())
240242
})
241243

@@ -245,10 +247,21 @@ func TestReconcileBatchJob(t *testing.T) {
245247
mockManagerClient.EXPECT().GetTrialObservationLog(gomock.Any()).Return(observationLogAvailable, nil).MinTimes(1),
246248
mockManagerClient.EXPECT().DeleteTrialObservationLog(gomock.Any()).Return(nil, nil),
247249
)
250+
251+
// Create the Trial with StdOut MC
252+
trial := newFakeTrialBatchJob(commonv1beta1.StdOutCollector, "test-available-stdout")
253+
trialKey := types.NamespacedName{Name: "test-available-stdout", Namespace: namespace}
248254
batchJob := &batchv1.Job{}
255+
g.Expect(c.Create(ctx, trial)).NotTo(gomega.HaveOccurred())
256+
257+
// Expect that BatchJob with appropriate name is created
258+
g.Eventually(func(g gomega.Gomega) {
259+
g.Expect(c.Get(ctx, batchJobKey, batchJob)).Should(gomega.Succeed())
260+
}, timeout).Should(gomega.Succeed())
261+
262+
// Update BatchJob status to Complete.
249263
batchJobCompleteMessage := "BatchJob completed test message"
250264
batchJobCompleteReason := "BatchJob completed test reason"
251-
// Update BatchJob status to Complete.
252265
g.Expect(c.Get(ctx, batchJobKey, batchJob)).NotTo(gomega.HaveOccurred())
253266
batchJob.Status = batchv1.JobStatus{
254267
Conditions: []batchv1.JobCondition{
@@ -269,11 +282,6 @@ func TestReconcileBatchJob(t *testing.T) {
269282
}
270283
g.Expect(c.Status().Update(ctx, batchJob)).NotTo(gomega.HaveOccurred())
271284

272-
// Create the Trial with StdOut MC
273-
trial := newFakeTrialBatchJob(commonv1beta1.StdOutCollector, "test-available-stdout")
274-
trialKey := types.NamespacedName{Name: "test-available-stdout", Namespace: namespace}
275-
g.Expect(c.Create(ctx, trial)).NotTo(gomega.HaveOccurred())
276-
277285
// Expect that Trial status is succeeded and metrics are properly populated
278286
// Metrics available because GetTrialObservationLog returns values
279287
g.Eventually(func(g gomega.Gomega) {

0 commit comments

Comments
 (0)