@@ -17,7 +17,6 @@ limitations under the License.
17
17
package experiment
18
18
19
19
import (
20
- "context"
21
20
"fmt"
22
21
"sync"
23
22
"testing"
@@ -184,7 +183,7 @@ func TestReconcile(t *testing.T) {
184
183
// Try to update status until it be succeeded
185
184
for err != nil {
186
185
updatedInstance := & experimentsv1beta1.Experiment {}
187
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, updatedInstance ); err != nil {
186
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, updatedInstance ); err != nil {
188
187
continue
189
188
}
190
189
updatedInstance .Status = instance .Status
@@ -201,7 +200,7 @@ func TestReconcile(t *testing.T) {
201
200
wg .Add (1 )
202
201
go func () {
203
202
defer wg .Done ()
204
- g .Expect (mgr .Start (context . TODO () )).NotTo (gomega .HaveOccurred ())
203
+ g .Expect (mgr .Start (ctx )).NotTo (gomega .HaveOccurred ())
205
204
}()
206
205
207
206
returnedBatchJob := newFakeBatchJob ()
@@ -245,11 +244,11 @@ func TestReconcile(t *testing.T) {
245
244
suggestion := & suggestionsv1beta1.Suggestion {}
246
245
// We should Get suggestion because resource version can be modified
247
246
for err != nil {
248
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
247
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
249
248
continue
250
249
}
251
250
suggestion .Status .Suggestions = suggestion .Status .Suggestions [1 :]
252
- err = c .Status ().Update (context . TODO () , suggestion )
251
+ err = c .Status ().Update (ctx , suggestion )
253
252
}
254
253
})
255
254
@@ -259,11 +258,11 @@ func TestReconcile(t *testing.T) {
259
258
var err error = errors .NewBadRequest ("fake-error" )
260
259
suggestion := & suggestionsv1beta1.Suggestion {}
261
260
for err != nil {
262
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
261
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
263
262
continue
264
263
}
265
264
suggestion .MarkSuggestionStatusSucceeded (reasonRestart , msgRestartNo )
266
- err = c .Status ().Update (context . TODO () , suggestion )
265
+ err = c .Status ().Update (ctx , suggestion )
267
266
}
268
267
})
269
268
@@ -273,11 +272,11 @@ func TestReconcile(t *testing.T) {
273
272
var err error = errors .NewBadRequest ("fake-error" )
274
273
suggestion := & suggestionsv1beta1.Suggestion {}
275
274
for err != nil {
276
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
275
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
277
276
continue
278
277
}
279
278
suggestion .MarkSuggestionStatusSucceeded (reasonRestart , msgRestartYes )
280
- err = c .Status ().Update (context . TODO () , suggestion )
279
+ err = c .Status ().Update (ctx , suggestion )
281
280
}
282
281
})
283
282
@@ -287,11 +286,11 @@ func TestReconcile(t *testing.T) {
287
286
suggestion := & suggestionsv1beta1.Suggestion {}
288
287
var err error = errors .NewBadRequest ("fake-error" )
289
288
for err != nil {
290
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
289
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
291
290
continue
292
291
}
293
292
suggestion .MarkSuggestionStatusRunning (corev1 .ConditionFalse , suggestionsv1beta1 .SuggestionRestartReason , msgRestarting )
294
- err = c .Status ().Update (context . TODO () , suggestion )
293
+ err = c .Status ().Update (ctx , suggestion )
295
294
}
296
295
})
297
296
@@ -306,27 +305,27 @@ func TestReconcile(t *testing.T) {
306
305
307
306
// Create the suggestion with NeverResume
308
307
suggestionInstance := newFakeSuggestion ()
309
- g .Expect (c .Create (context . TODO () , suggestionInstance )).NotTo (gomega .HaveOccurred ())
308
+ g .Expect (c .Create (ctx , suggestionInstance )).NotTo (gomega .HaveOccurred ())
310
309
// Manually update suggestion's status with 3 suggestions
311
310
// Ones redundant trial is deleted, suggestion status must be updated
312
311
g .Eventually (func () error {
313
312
suggestion := & suggestionsv1beta1.Suggestion {}
314
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
313
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
315
314
return err
316
315
}
317
316
suggestion .Status .Suggestions = newFakeSuggestion ().Status .Suggestions
318
- errStatus := c .Status ().Update (context . TODO () , suggestion )
317
+ errStatus := c .Status ().Update (ctx , suggestion )
319
318
return errStatus
320
319
}, timeout ).ShouldNot (gomega .HaveOccurred ())
321
320
322
321
// Create the experiment
323
322
instance := newFakeInstance ()
324
- g .Expect (c .Create (context . TODO () , instance )).NotTo (gomega .HaveOccurred ())
323
+ g .Expect (c .Create (ctx , instance )).NotTo (gomega .HaveOccurred ())
325
324
326
325
// Expect that experiment status is running
327
326
experiment := & experimentsv1beta1.Experiment {}
328
327
g .Eventually (func () bool {
329
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
328
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
330
329
return false
331
330
}
332
331
return experiment .IsRunning ()
@@ -338,7 +337,7 @@ func TestReconcile(t *testing.T) {
338
337
label := labels.Set {
339
338
consts .LabelExperimentName : experimentName ,
340
339
}
341
- g .Expect (c .List (context . TODO () , trials , & client.ListOptions {LabelSelector : label .AsSelector ()})).NotTo (gomega .HaveOccurred ())
340
+ g .Expect (c .List (ctx , trials , & client.ListOptions {LabelSelector : label .AsSelector ()})).NotTo (gomega .HaveOccurred ())
342
341
return len (trials .Items )
343
342
}, timeout ).Should (gomega .Equal (2 ))
344
343
@@ -348,7 +347,7 @@ func TestReconcile(t *testing.T) {
348
347
g .Eventually (func () bool {
349
348
suggestion := & suggestionsv1beta1.Suggestion {}
350
349
isDeleted := true
351
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
350
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
352
351
return false
353
352
}
354
353
for _ , s := range suggestion .Status .Suggestions {
@@ -365,38 +364,38 @@ func TestReconcile(t *testing.T) {
365
364
g .Eventually (func () bool {
366
365
// Update experiment
367
366
experiment = & experimentsv1beta1.Experiment {}
368
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
367
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
369
368
return false
370
369
}
371
370
experiment .MarkExperimentStatusFailed (experimentUtil .ExperimentMaxTrialsReachedReason , "Experiment is failed" )
372
- if err = c .Status ().Update (context . TODO () , experiment ); err != nil {
371
+ if err = c .Status ().Update (ctx , experiment ); err != nil {
373
372
return false
374
373
}
375
374
376
375
// Get Suggestion
377
376
suggestion := & suggestionsv1beta1.Suggestion {}
378
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
377
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, suggestion ); err != nil {
379
378
return false
380
379
}
381
380
return suggestion .IsSucceeded ()
382
381
}, timeout ).Should (gomega .BeTrue ())
383
382
384
383
// Delete the suggestion
385
- g .Expect (c .Delete (context . TODO () , suggestionInstance )).NotTo (gomega .HaveOccurred ())
384
+ g .Expect (c .Delete (ctx , suggestionInstance )).NotTo (gomega .HaveOccurred ())
386
385
387
386
// Expect that suggestion with ResumePolicy = NeverResume is deleted
388
387
g .Eventually (func () bool {
389
- return errors .IsNotFound (c .Get (context . TODO () ,
388
+ return errors .IsNotFound (c .Get (ctx ,
390
389
types.NamespacedName {Namespace : namespace , Name : experimentName }, & suggestionsv1beta1.Suggestion {}))
391
390
}, timeout ).Should (gomega .BeTrue ())
392
391
393
392
// Create the suggestion with ResumePolicy = FromVolume
394
393
suggestionInstance = newFakeSuggestion ()
395
394
suggestionInstance .Spec .ResumePolicy = experimentsv1beta1 .FromVolume
396
- g .Expect (c .Create (context . TODO () , suggestionInstance )).NotTo (gomega .HaveOccurred ())
395
+ g .Expect (c .Create (ctx , suggestionInstance )).NotTo (gomega .HaveOccurred ())
397
396
// Expect that suggestion is created
398
397
g .Eventually (func () bool {
399
- return errors .IsNotFound (c .Get (context . TODO () ,
398
+ return errors .IsNotFound (c .Get (ctx ,
400
399
types.NamespacedName {Namespace : namespace , Name : experimentName }, & suggestionsv1beta1.Suggestion {}))
401
400
}, timeout ).ShouldNot (gomega .BeTrue ())
402
401
@@ -405,25 +404,25 @@ func TestReconcile(t *testing.T) {
405
404
g .Eventually (func () bool {
406
405
experiment := & experimentsv1beta1.Experiment {}
407
406
// Update ResumePolicy and maxTrialCount for resume
408
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
407
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
409
408
return false
410
409
}
411
410
experiment .Spec .ResumePolicy = experimentsv1beta1 .FromVolume
412
411
var max int32 = 5
413
412
experiment .Spec .MaxTrialCount = & max
414
- errUpdate := c .Update (context . TODO () , experiment )
413
+ errUpdate := c .Update (ctx , experiment )
415
414
return errUpdate == nil
416
415
}, timeout ).Should (gomega .BeTrue ())
417
416
418
417
// Expect that experiment status is updated
419
418
g .Eventually (func () bool {
420
419
experiment := & experimentsv1beta1.Experiment {}
421
420
// Update status to succeeded
422
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
421
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
423
422
return false
424
423
}
425
424
experiment .MarkExperimentStatusSucceeded (experimentUtil .ExperimentMaxTrialsReachedReason , "Experiment is succeeded" )
426
- errStatus := c .Status ().Update (context . TODO () , experiment )
425
+ errStatus := c .Status ().Update (ctx , experiment )
427
426
return errStatus == nil
428
427
}, timeout ).Should (gomega .BeTrue ())
429
428
@@ -432,27 +431,27 @@ func TestReconcile(t *testing.T) {
432
431
// UpdateSuggestionStatus with restartYesCall call and UpdateSuggestionStatus with experimentRestartingCall call.
433
432
g .Eventually (func () bool {
434
433
experiment := & experimentsv1beta1.Experiment {}
435
- if err = c .Get (context . TODO () , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
434
+ if err = c .Get (ctx , types.NamespacedName {Namespace : namespace , Name : experimentName }, experiment ); err != nil {
436
435
return false
437
436
}
438
437
return experiment .IsRestarting () && ! experiment .IsSucceeded () && ! experiment .IsFailed ()
439
438
}, timeout ).Should (gomega .BeTrue ())
440
439
441
440
// Delete the suggestion
442
- g .Expect (c .Delete (context . TODO () , suggestionInstance )).NotTo (gomega .HaveOccurred ())
441
+ g .Expect (c .Delete (ctx , suggestionInstance )).NotTo (gomega .HaveOccurred ())
443
442
444
443
// Expect that suggestion with ResumePolicy = FromVolume is deleted
445
444
g .Eventually (func () bool {
446
- return errors .IsNotFound (c .Get (context . TODO () ,
445
+ return errors .IsNotFound (c .Get (ctx ,
447
446
types.NamespacedName {Namespace : namespace , Name : experimentName }, & suggestionsv1beta1.Suggestion {}))
448
447
}, timeout ).Should (gomega .BeTrue ())
449
448
450
449
// Delete the experiment
451
- g .Expect (c .Delete (context . TODO () , instance )).NotTo (gomega .HaveOccurred ())
450
+ g .Expect (c .Delete (ctx , instance )).NotTo (gomega .HaveOccurred ())
452
451
453
452
// Expect that experiment is deleted
454
453
g .Eventually (func () bool {
455
- return errors .IsNotFound (c .Get (context . TODO () ,
454
+ return errors .IsNotFound (c .Get (ctx ,
456
455
types.NamespacedName {Namespace : namespace , Name : experimentName }, & experimentsv1beta1.Experiment {}))
457
456
}, timeout ).Should (gomega .BeTrue ())
458
457
0 commit comments