@@ -187,24 +187,20 @@ func TestReconcileBatchJob(t *testing.T) {
187
187
g .Expect (c .Create (ctx , trial )).NotTo (gomega .HaveOccurred ())
188
188
189
189
// Expect that BatchJob with appropriate name is created
190
- g .Eventually (func () error {
191
- return c .Get (ctx , batchJobKey , batchJob )
190
+ g .Eventually (func (g gomega. Gomega ) {
191
+ g . Expect ( c .Get (ctx , batchJobKey , batchJob )). Should ( gomega . Succeed () )
192
192
}, timeout ).Should (gomega .Succeed ())
193
193
194
194
// Expect that Trial status is running
195
- g .Eventually (func () bool {
196
- if err = c .Get (ctx , trialKey , trial ); err != nil {
197
- return false
198
- }
199
- return trial .IsRunning ()
200
- }, timeout ).Should (gomega .BeTrue ())
195
+ g .Eventually (func (g gomega.Gomega ) {
196
+ g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
197
+ g .Expect (trial .IsRunning ()).Should (gomega .BeTrue ())
198
+ }, timeout ).Should (gomega .Succeed ())
201
199
202
200
// Manually update BatchJob status to failed
203
201
// Expect that Trial status is failed
204
- g .Eventually (func () bool {
205
- if err = c .Get (ctx , batchJobKey , batchJob ); err != nil {
206
- return false
207
- }
202
+ g .Eventually (func (g gomega.Gomega ) {
203
+ g .Expect (c .Get (ctx , batchJobKey , batchJob )).Should (gomega .Succeed ())
208
204
batchJob .Status = batchv1.JobStatus {
209
205
Conditions : []batchv1.JobCondition {
210
206
{
@@ -215,25 +211,20 @@ func TestReconcileBatchJob(t *testing.T) {
215
211
},
216
212
},
217
213
}
218
- if err = c .Status ().Update (ctx , batchJob ); err != nil {
219
- return false
220
- }
221
-
222
- if err = c .Get (ctx , trialKey , trial ); err != nil {
223
- return false
224
- }
225
- return trial .IsFailed ()
226
- }, timeout ).Should (gomega .BeTrue ())
214
+ g .Expect (c .Status ().Update (ctx , batchJob )).Should (gomega .Succeed ())
215
+ g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
216
+ g .Expect (trial .IsFailed ()).Should (gomega .BeTrue ())
217
+ }, timeout ).Should (gomega .Succeed ())
227
218
228
219
// Delete the Trial
229
220
g .Expect (c .Delete (ctx , trial )).NotTo (gomega .HaveOccurred ())
230
221
231
222
// Expect that Trial is deleted
232
223
// BatchJob can't be deleted because GC doesn't work in envtest and BatchJob stuck in termination phase.
233
224
// Ref: https://book.kubebuilder.io/reference/testing/envtest.html#testing-considerations.
234
- g .Eventually (func () bool {
235
- return errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))
236
- }, timeout ).Should (gomega .BeTrue ())
225
+ g .Eventually (func (g gomega. Gomega ) {
226
+ g . Expect ( errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))). Should ( gomega . BeTrue ( ))
227
+ }, timeout ).Should (gomega .Succeed ())
237
228
})
238
229
239
230
t .Run (`Trial with "Complete" BatchJob and Available metrics.` , func (t * testing.T ) {
@@ -266,26 +257,25 @@ func TestReconcileBatchJob(t *testing.T) {
266
257
267
258
// Expect that Trial status is succeeded and metrics are properly populated
268
259
// Metrics available because GetTrialObservationLog returns values
269
- start := time .Now ()
270
- g .Eventually (func () bool {
271
- if err = c .Get (ctx , trialKey , trial ); err != nil {
272
- t .Log (time .Since (start ), err )
273
- return false
274
- }
275
- return trial .IsSucceeded () &&
276
- len (trial .Status .Observation .Metrics ) > 0 &&
277
- trial .Status .Observation .Metrics [0 ].Min == "0.11" &&
278
- trial .Status .Observation .Metrics [0 ].Max == "0.99" &&
279
- trial .Status .Observation .Metrics [0 ].Latest == "0.11"
280
- }, timeout ).Should (gomega .BeTrue ())
260
+ g .Eventually (func (g gomega.Gomega ) {
261
+ g .Expect (c .Get (ctx , trialKey , trial )).Should (gomega .Succeed ())
262
+ g .Expect (trial .IsSucceeded ()).Should (gomega .BeTrue ())
263
+ g .Expect (trial .Status .Observation .Metrics ).ShouldNot (gomega .HaveLen (0 ))
264
+ g .Expect (trial .Status .Observation .Metrics [0 ]).Should (gomega .BeComparableTo (commonv1beta1.Metric {
265
+ Name : objectiveMetric ,
266
+ Min : "0.11" ,
267
+ Max : "0.99" ,
268
+ Latest : "0.11" ,
269
+ }))
270
+ }, timeout ).Should (gomega .Succeed ())
281
271
282
272
// Delete the Trial
283
273
g .Expect (c .Delete (ctx , trial )).NotTo (gomega .HaveOccurred ())
284
274
285
275
// Expect that Trial is deleted
286
- g .Eventually (func () bool {
287
- return errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))
288
- }, timeout ).Should (gomega .BeTrue ())
276
+ g .Eventually (func (g gomega. Gomega ) {
277
+ g . Expect ( errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))). Should ( gomega . BeTrue ( ))
278
+ }, timeout ).Should (gomega .Succeed ())
289
279
})
290
280
291
281
t .Run (`Trial with "Complete" BatchJob and Unavailable metrics(StdOut MC).` , func (t * testing.T ) {
@@ -317,9 +307,9 @@ func TestReconcileBatchJob(t *testing.T) {
317
307
g .Expect (c .Delete (ctx , trial )).NotTo (gomega .HaveOccurred ())
318
308
319
309
// Expect that Trial is deleted
320
- g .Eventually (func () bool {
321
- return errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))
322
- }, timeout ).Should (gomega .BeTrue ())
310
+ g .Eventually (func (g gomega. Gomega ) {
311
+ g . Expect ( errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))). Should ( gomega . BeTrue ( ))
312
+ }, timeout ).Should (gomega .Succeed ())
323
313
})
324
314
325
315
t .Run (`Trial with "Complete" BatchJob and Unavailable metrics(Push MC, failed once).` , func (t * testing.T ) {
@@ -358,9 +348,9 @@ func TestReconcileBatchJob(t *testing.T) {
358
348
g .Expect (c .Delete (ctx , trial )).NotTo (gomega .HaveOccurred ())
359
349
360
350
// Expect that Trial is deleted
361
- g .Eventually (func () bool {
362
- return errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))
363
- }, timeout ).Should (gomega .BeTrue ())
351
+ g .Eventually (func (g gomega. Gomega ) {
352
+ g . Expect ( errors .IsNotFound (c .Get (ctx , trialKey , & trialsv1beta1.Trial {}))). Should ( gomega . BeTrue ( ))
353
+ }, timeout ).Should (gomega .Succeed ())
364
354
})
365
355
366
356
t .Run ("Update status for empty Trial" , func (t * testing.T ) {
0 commit comments