@@ -228,14 +228,16 @@ func TestReconcileBatchJob(t *testing.T) {
228
228
g .Expect (trial .IsFailed ()).Should (gomega .BeTrue ())
229
229
}, timeout ).Should (gomega .Succeed ())
230
230
231
- // Delete the Trial
231
+ // Delete the Trial and Job
232
232
g .Expect (c .Delete (ctx , trial )).NotTo (gomega .HaveOccurred ())
233
+ g .Expect (c .Delete (ctx , batchJob )).NotTo (gomega .HaveOccurred ())
233
234
234
235
// Expect that Trial is deleted
235
236
// BatchJob can't be deleted because GC doesn't work in envtest and BatchJob stuck in termination phase.
236
237
// Ref: https://book.kubebuilder.io/reference/testing/envtest.html#testing-considerations.
237
238
g .Eventually (func (g gomega.Gomega ) {
238
239
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 ())
239
241
}, timeout ).Should (gomega .Succeed ())
240
242
})
241
243
@@ -245,10 +247,21 @@ func TestReconcileBatchJob(t *testing.T) {
245
247
mockManagerClient .EXPECT ().GetTrialObservationLog (gomock .Any ()).Return (observationLogAvailable , nil ).MinTimes (1 ),
246
248
mockManagerClient .EXPECT ().DeleteTrialObservationLog (gomock .Any ()).Return (nil , nil ),
247
249
)
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 }
248
254
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.
249
263
batchJobCompleteMessage := "BatchJob completed test message"
250
264
batchJobCompleteReason := "BatchJob completed test reason"
251
- // Update BatchJob status to Complete.
252
265
g .Expect (c .Get (ctx , batchJobKey , batchJob )).NotTo (gomega .HaveOccurred ())
253
266
batchJob .Status = batchv1.JobStatus {
254
267
Conditions : []batchv1.JobCondition {
@@ -269,11 +282,6 @@ func TestReconcileBatchJob(t *testing.T) {
269
282
}
270
283
g .Expect (c .Status ().Update (ctx , batchJob )).NotTo (gomega .HaveOccurred ())
271
284
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
-
277
285
// Expect that Trial status is succeeded and metrics are properly populated
278
286
// Metrics available because GetTrialObservationLog returns values
279
287
g .Eventually (func (g gomega.Gomega ) {
0 commit comments