@@ -56,6 +56,7 @@ const (
56
56
)
57
57
58
58
var (
59
+ startTime = time .Now ()
59
60
batchJobKey = types.NamespacedName {Name : batchJobName , Namespace : namespace }
60
61
observationLogAvailable = & api_pb.GetObservationLogReply {
61
62
ObservationLog : & api_pb.ObservationLog {
@@ -180,67 +181,6 @@ func TestReconcileBatchJob(t *testing.T) {
180
181
g .Expect (mgr .Start (mgrCtx )).NotTo (gomega .HaveOccurred ())
181
182
}()
182
183
183
- t .Run (`Trial run with "Failed" BatchJob.` , func (t * testing.T ) {
184
- g := gomega .NewGomegaWithT (t )
185
- mockManagerClient .EXPECT ().DeleteTrialObservationLog (gomock .Any ()).Return (nil , nil )
186
-
187
- trial := newFakeTrialBatchJob (commonv1beta1 .StdOutCollector , "test-failed-batch-job" )
188
- trialKey := types.NamespacedName {Name : "test-failed-batch-job" , Namespace : namespace }
189
- batchJob := & batchv1.Job {}
190
-
191
- // Create the Trial with StdOut MC
192
- g .Expect (c .Create (ctx , trial )).NotTo (gomega .HaveOccurred ())
193
-
194
- // Expect that BatchJob with appropriate name is created
195
- g .Eventually (func (g gomega.Gomega ) {
196
- g .Expect (c .Get (ctx , batchJobKey , batchJob )).Should (gomega .Succeed ())
197
- }, timeout ).Should (gomega .Succeed ())
198
-
199
- // Expect that Trial status is running
200
- g .Eventually (func (g gomega.Gomega ) {
201
- g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
202
- g .Expect (trial .IsRunning ()).Should (gomega .BeTrue ())
203
- }, timeout ).Should (gomega .Succeed ())
204
-
205
- // Manually update BatchJob status to failed
206
- // Expect that Trial status is failed
207
- g .Eventually (func (g gomega.Gomega ) {
208
- g .Expect (c .Get (ctx , batchJobKey , batchJob )).Should (gomega .Succeed ())
209
- batchJob .Status = batchv1.JobStatus {
210
- Conditions : []batchv1.JobCondition {
211
- {
212
- Type : batchv1 .JobFailureTarget ,
213
- Status : corev1 .ConditionTrue ,
214
- Message : "BatchJob failed test message" ,
215
- Reason : "BatchJob failed test reason" ,
216
- },
217
- {
218
- Type : batchv1 .JobFailed ,
219
- Status : corev1 .ConditionTrue ,
220
- Message : "BatchJob failed test message" ,
221
- Reason : "BatchJob failed test reason" ,
222
- },
223
- },
224
- StartTime : & metav1.Time {Time : time .Now ()},
225
- }
226
- g .Expect (c .Status ().Update (ctx , batchJob )).Should (gomega .Succeed ())
227
- g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
228
- g .Expect (trial .IsFailed ()).Should (gomega .BeTrue ())
229
- }, timeout ).Should (gomega .Succeed ())
230
-
231
- // Delete the Trial and Job
232
- g .Expect (c .Delete (ctx , trial )).NotTo (gomega .HaveOccurred ())
233
- g .Expect (c .Delete (ctx , batchJob )).NotTo (gomega .HaveOccurred ())
234
-
235
- // Expect that Trial is deleted
236
- // BatchJob can't be deleted because GC doesn't work in envtest and BatchJob stuck in termination phase.
237
- // Ref: https://book.kubebuilder.io/reference/testing/envtest.html#testing-considerations.
238
- g .Eventually (func (g gomega.Gomega ) {
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 ())
241
- }, timeout ).Should (gomega .Succeed ())
242
- })
243
-
244
184
t .Run (`Trial with "Complete" BatchJob and Available metrics.` , func (t * testing.T ) {
245
185
g := gomega .NewGomegaWithT (t )
246
186
gomock .InOrder (
@@ -258,7 +198,7 @@ func TestReconcileBatchJob(t *testing.T) {
258
198
g .Eventually (func (g gomega.Gomega ) {
259
199
g .Expect (c .Get (ctx , batchJobKey , batchJob )).Should (gomega .Succeed ())
260
200
}, timeout ).Should (gomega .Succeed ())
261
-
201
+
262
202
// Update BatchJob status to Complete.
263
203
batchJobCompleteMessage := "BatchJob completed test message"
264
204
batchJobCompleteReason := "BatchJob completed test reason"
@@ -269,7 +209,7 @@ func TestReconcileBatchJob(t *testing.T) {
269
209
Type : batchv1 .JobSuccessCriteriaMet ,
270
210
Status : corev1 .ConditionTrue ,
271
211
Message : batchJobCompleteMessage ,
272
- Reason : batchv1 . JobReasonSuccessPolicy ,
212
+ Reason : batchJobCompleteReason ,
273
213
},
274
214
{
275
215
Type : batchv1 .JobComplete ,
@@ -278,7 +218,7 @@ func TestReconcileBatchJob(t *testing.T) {
278
218
Reason : batchJobCompleteReason ,
279
219
},
280
220
},
281
- StartTime : & metav1.Time {Time : time . Now () },
221
+ StartTime : & metav1.Time {Time : startTime },
282
222
}
283
223
g .Expect (c .Status ().Update (ctx , batchJob )).NotTo (gomega .HaveOccurred ())
284
224
@@ -380,10 +320,78 @@ func TestReconcileBatchJob(t *testing.T) {
380
320
}, timeout ).Should (gomega .Succeed ())
381
321
})
382
322
323
+ t .Run (`Trial run with "Failed" BatchJob.` , func (t * testing.T ) {
324
+ g := gomega .NewGomegaWithT (t )
325
+ mockManagerClient .EXPECT ().DeleteTrialObservationLog (gomock .Any ()).Return (nil , nil )
326
+
327
+ trial := newFakeTrialBatchJob (commonv1beta1 .StdOutCollector , "test-failed-batch-job" )
328
+ trialKey := types.NamespacedName {Name : "test-failed-batch-job" , Namespace : namespace }
329
+ batchJob := & batchv1.Job {}
330
+
331
+ // Create the Trial with StdOut MC
332
+ g .Expect (c .Create (ctx , trial )).NotTo (gomega .HaveOccurred ())
333
+
334
+ // Expect that BatchJob with appropriate name is created
335
+ g .Eventually (func (g gomega.Gomega ) {
336
+ g .Expect (c .Get (ctx , batchJobKey , batchJob )).Should (gomega .Succeed ())
337
+ }, timeout ).Should (gomega .Succeed ())
338
+
339
+ // Expect that Trial status is running
340
+ g .Eventually (func (g gomega.Gomega ) {
341
+ g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
342
+ g .Expect (trial .IsRunning ()).Should (gomega .BeTrue ())
343
+ }, timeout ).Should (gomega .Succeed ())
344
+
345
+ // Manually update BatchJob status to failed
346
+ // Expect that Trial status is failed
347
+ batchJobFailedMessage := "BatchJob completed test message"
348
+ batchJobFailedReason := "BatchJob completed test reason"
349
+ g .Eventually (func (g gomega.Gomega ) {
350
+ g .Expect (c .Get (ctx , batchJobKey , batchJob )).Should (gomega .Succeed ())
351
+ batchJob .Status = batchv1.JobStatus {
352
+ Conditions : []batchv1.JobCondition {
353
+ {
354
+ Type : batchv1 .JobFailureTarget ,
355
+ Status : corev1 .ConditionTrue ,
356
+ Message : batchJobFailedMessage ,
357
+ Reason : batchJobFailedReason ,
358
+ },
359
+ {
360
+ Type : batchv1 .JobFailed ,
361
+ Status : corev1 .ConditionTrue ,
362
+ Message : batchJobFailedMessage ,
363
+ Reason : batchJobFailedReason ,
364
+ },
365
+ {
366
+ Type : batchv1 .JobSuccessCriteriaMet ,
367
+ Status : corev1 .ConditionFalse ,
368
+ Message : batchJobFailedMessage ,
369
+ Reason : batchJobFailedReason ,
370
+ },
371
+ },
372
+ StartTime : & metav1.Time {Time : startTime },
373
+ }
374
+ g .Expect (c .Status ().Update (ctx , batchJob )).Should (gomega .Succeed ())
375
+ g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
376
+ g .Expect (trial .IsFailed ()).Should (gomega .BeTrue ())
377
+ }, timeout ).Should (gomega .Succeed ())
378
+
379
+ // Delete the Trial
380
+ g .Expect (c .Delete (ctx , trial )).NotTo (gomega .HaveOccurred ())
381
+
382
+ // Expect that Trial is deleted
383
+ // BatchJob can't be deleted because GC doesn't work in envtest and BatchJob stuck in termination phase.
384
+ // Ref: https://book.kubebuilder.io/reference/testing/envtest.html#testing-considerations.
385
+ g .Eventually (func (g gomega.Gomega ) {
386
+ g .Expect (errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))).Should (gomega .BeTrue ())
387
+ }, timeout ).Should (gomega .Succeed ())
388
+ })
389
+
383
390
t .Run ("Update status for empty Trial" , func (t * testing.T ) {
384
391
g := gomega .NewGomegaWithT (t )
385
392
g .Expect (r .updateStatus (& trialsv1beta1.Trial {})).To (gomega .HaveOccurred ())
386
393
})
394
+
387
395
}
388
396
389
397
func TestGetObjectiveMetricValue (t * testing.T ) {
0 commit comments