@@ -17,7 +17,6 @@ limitations under the License.
1717package experiment
1818
1919import (
20- "context"
2120 "fmt"
2221 "sync"
2322 "testing"
@@ -184,7 +183,7 @@ func TestReconcile(t *testing.T) {
184183 // Try to update status until it be succeeded
185184 for err != nil {
186185 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 {
188187 continue
189188 }
190189 updatedInstance .Status = instance .Status
@@ -201,7 +200,7 @@ func TestReconcile(t *testing.T) {
201200 wg .Add (1 )
202201 go func () {
203202 defer wg .Done ()
204- g .Expect (mgr .Start (context . TODO () )).NotTo (gomega .HaveOccurred ())
203+ g .Expect (mgr .Start (ctx )).NotTo (gomega .HaveOccurred ())
205204 }()
206205
207206 returnedBatchJob := newFakeBatchJob ()
@@ -245,11 +244,11 @@ func TestReconcile(t *testing.T) {
245244 suggestion := & suggestionsv1beta1.Suggestion {}
246245 // We should Get suggestion because resource version can be modified
247246 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 {
249248 continue
250249 }
251250 suggestion .Status .Suggestions = suggestion .Status .Suggestions [1 :]
252- err = c .Status ().Update (context . TODO () , suggestion )
251+ err = c .Status ().Update (ctx , suggestion )
253252 }
254253 })
255254
@@ -259,11 +258,11 @@ func TestReconcile(t *testing.T) {
259258 var err error = errors .NewBadRequest ("fake-error" )
260259 suggestion := & suggestionsv1beta1.Suggestion {}
261260 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 {
263262 continue
264263 }
265264 suggestion .MarkSuggestionStatusSucceeded (reasonRestart , msgRestartNo )
266- err = c .Status ().Update (context . TODO () , suggestion )
265+ err = c .Status ().Update (ctx , suggestion )
267266 }
268267 })
269268
@@ -273,11 +272,11 @@ func TestReconcile(t *testing.T) {
273272 var err error = errors .NewBadRequest ("fake-error" )
274273 suggestion := & suggestionsv1beta1.Suggestion {}
275274 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 {
277276 continue
278277 }
279278 suggestion .MarkSuggestionStatusSucceeded (reasonRestart , msgRestartYes )
280- err = c .Status ().Update (context . TODO () , suggestion )
279+ err = c .Status ().Update (ctx , suggestion )
281280 }
282281 })
283282
@@ -287,11 +286,11 @@ func TestReconcile(t *testing.T) {
287286 suggestion := & suggestionsv1beta1.Suggestion {}
288287 var err error = errors .NewBadRequest ("fake-error" )
289288 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 {
291290 continue
292291 }
293292 suggestion .MarkSuggestionStatusRunning (corev1 .ConditionFalse , suggestionsv1beta1 .SuggestionRestartReason , msgRestarting )
294- err = c .Status ().Update (context . TODO () , suggestion )
293+ err = c .Status ().Update (ctx , suggestion )
295294 }
296295 })
297296
@@ -306,27 +305,27 @@ func TestReconcile(t *testing.T) {
306305
307306 // Create the suggestion with NeverResume
308307 suggestionInstance := newFakeSuggestion ()
309- g .Expect (c .Create (context . TODO () , suggestionInstance )).NotTo (gomega .HaveOccurred ())
308+ g .Expect (c .Create (ctx , suggestionInstance )).NotTo (gomega .HaveOccurred ())
310309 // Manually update suggestion's status with 3 suggestions
311310 // Ones redundant trial is deleted, suggestion status must be updated
312311 g .Eventually (func () error {
313312 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 {
315314 return err
316315 }
317316 suggestion .Status .Suggestions = newFakeSuggestion ().Status .Suggestions
318- errStatus := c .Status ().Update (context . TODO () , suggestion )
317+ errStatus := c .Status ().Update (ctx , suggestion )
319318 return errStatus
320319 }, timeout ).ShouldNot (gomega .HaveOccurred ())
321320
322321 // Create the experiment
323322 instance := newFakeInstance ()
324- g .Expect (c .Create (context . TODO () , instance )).NotTo (gomega .HaveOccurred ())
323+ g .Expect (c .Create (ctx , instance )).NotTo (gomega .HaveOccurred ())
325324
326325 // Expect that experiment status is running
327326 experiment := & experimentsv1beta1.Experiment {}
328327 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 {
330329 return false
331330 }
332331 return experiment .IsRunning ()
@@ -338,7 +337,7 @@ func TestReconcile(t *testing.T) {
338337 label := labels.Set {
339338 consts .LabelExperimentName : experimentName ,
340339 }
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 ())
342341 return len (trials .Items )
343342 }, timeout ).Should (gomega .Equal (2 ))
344343
@@ -348,7 +347,7 @@ func TestReconcile(t *testing.T) {
348347 g .Eventually (func () bool {
349348 suggestion := & suggestionsv1beta1.Suggestion {}
350349 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 {
352351 return false
353352 }
354353 for _ , s := range suggestion .Status .Suggestions {
@@ -365,38 +364,38 @@ func TestReconcile(t *testing.T) {
365364 g .Eventually (func () bool {
366365 // Update experiment
367366 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 {
369368 return false
370369 }
371370 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 {
373372 return false
374373 }
375374
376375 // Get Suggestion
377376 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 {
379378 return false
380379 }
381380 return suggestion .IsSucceeded ()
382381 }, timeout ).Should (gomega .BeTrue ())
383382
384383 // Delete the suggestion
385- g .Expect (c .Delete (context . TODO () , suggestionInstance )).NotTo (gomega .HaveOccurred ())
384+ g .Expect (c .Delete (ctx , suggestionInstance )).NotTo (gomega .HaveOccurred ())
386385
387386 // Expect that suggestion with ResumePolicy = NeverResume is deleted
388387 g .Eventually (func () bool {
389- return errors .IsNotFound (c .Get (context . TODO () ,
388+ return errors .IsNotFound (c .Get (ctx ,
390389 types.NamespacedName {Namespace : namespace , Name : experimentName }, & suggestionsv1beta1.Suggestion {}))
391390 }, timeout ).Should (gomega .BeTrue ())
392391
393392 // Create the suggestion with ResumePolicy = FromVolume
394393 suggestionInstance = newFakeSuggestion ()
395394 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 ())
397396 // Expect that suggestion is created
398397 g .Eventually (func () bool {
399- return errors .IsNotFound (c .Get (context . TODO () ,
398+ return errors .IsNotFound (c .Get (ctx ,
400399 types.NamespacedName {Namespace : namespace , Name : experimentName }, & suggestionsv1beta1.Suggestion {}))
401400 }, timeout ).ShouldNot (gomega .BeTrue ())
402401
@@ -405,25 +404,25 @@ func TestReconcile(t *testing.T) {
405404 g .Eventually (func () bool {
406405 experiment := & experimentsv1beta1.Experiment {}
407406 // 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 {
409408 return false
410409 }
411410 experiment .Spec .ResumePolicy = experimentsv1beta1 .FromVolume
412411 var max int32 = 5
413412 experiment .Spec .MaxTrialCount = & max
414- errUpdate := c .Update (context . TODO () , experiment )
413+ errUpdate := c .Update (ctx , experiment )
415414 return errUpdate == nil
416415 }, timeout ).Should (gomega .BeTrue ())
417416
418417 // Expect that experiment status is updated
419418 g .Eventually (func () bool {
420419 experiment := & experimentsv1beta1.Experiment {}
421420 // 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 {
423422 return false
424423 }
425424 experiment .MarkExperimentStatusSucceeded (experimentUtil .ExperimentMaxTrialsReachedReason , "Experiment is succeeded" )
426- errStatus := c .Status ().Update (context . TODO () , experiment )
425+ errStatus := c .Status ().Update (ctx , experiment )
427426 return errStatus == nil
428427 }, timeout ).Should (gomega .BeTrue ())
429428
@@ -432,27 +431,27 @@ func TestReconcile(t *testing.T) {
432431 // UpdateSuggestionStatus with restartYesCall call and UpdateSuggestionStatus with experimentRestartingCall call.
433432 g .Eventually (func () bool {
434433 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 {
436435 return false
437436 }
438437 return experiment .IsRestarting () && ! experiment .IsSucceeded () && ! experiment .IsFailed ()
439438 }, timeout ).Should (gomega .BeTrue ())
440439
441440 // Delete the suggestion
442- g .Expect (c .Delete (context . TODO () , suggestionInstance )).NotTo (gomega .HaveOccurred ())
441+ g .Expect (c .Delete (ctx , suggestionInstance )).NotTo (gomega .HaveOccurred ())
443442
444443 // Expect that suggestion with ResumePolicy = FromVolume is deleted
445444 g .Eventually (func () bool {
446- return errors .IsNotFound (c .Get (context . TODO () ,
445+ return errors .IsNotFound (c .Get (ctx ,
447446 types.NamespacedName {Namespace : namespace , Name : experimentName }, & suggestionsv1beta1.Suggestion {}))
448447 }, timeout ).Should (gomega .BeTrue ())
449448
450449 // Delete the experiment
451- g .Expect (c .Delete (context . TODO () , instance )).NotTo (gomega .HaveOccurred ())
450+ g .Expect (c .Delete (ctx , instance )).NotTo (gomega .HaveOccurred ())
452451
453452 // Expect that experiment is deleted
454453 g .Eventually (func () bool {
455- return errors .IsNotFound (c .Get (context . TODO () ,
454+ return errors .IsNotFound (c .Get (ctx ,
456455 types.NamespacedName {Namespace : namespace , Name : experimentName }, & experimentsv1beta1.Experiment {}))
457456 }, timeout ).Should (gomega .BeTrue ())
458457
0 commit comments