@@ -2756,6 +2756,8 @@ func getCondition(job *batch.Job, condition batch.JobConditionType, status v1.Co
2756
2756
// reaching the active deadline, at which point it is marked as Failed.
2757
2757
func TestPastDeadlineJobFinished (t * testing.T ) {
2758
2758
_ , ctx := ktesting .NewTestContext (t )
2759
+ ctx , cancel := context .WithCancel (ctx )
2760
+ t .Cleanup (cancel )
2759
2761
clientset := fake .NewClientset ()
2760
2762
fakeClock := clocktesting .NewFakeClock (time .Now ().Truncate (time .Second ))
2761
2763
manager , sharedInformerFactory := newControllerFromClientWithClock (ctx , t , clientset , controller .NoResyncPeriodFunc , fakeClock )
@@ -2765,8 +2767,6 @@ func TestPastDeadlineJobFinished(t *testing.T) {
2765
2767
controller .NewControllerExpectations (), true , func () {
2766
2768
},
2767
2769
}
2768
- ctx , cancel := context .WithCancel (context .Background ())
2769
- defer cancel ()
2770
2770
sharedInformerFactory .Start (ctx .Done ())
2771
2771
sharedInformerFactory .WaitForCacheSync (ctx .Done ())
2772
2772
@@ -6549,6 +6549,8 @@ func TestWatchPods(t *testing.T) {
6549
6549
6550
6550
func TestWatchOrphanPods (t * testing.T ) {
6551
6551
_ , ctx := ktesting .NewTestContext (t )
6552
+ ctx , cancel := context .WithCancel (ctx )
6553
+ t .Cleanup (cancel )
6552
6554
clientset := fake .NewClientset ()
6553
6555
sharedInformers := informers .NewSharedInformerFactory (clientset , controller .NoResyncPeriodFunc ())
6554
6556
manager , err := NewController (ctx , sharedInformers .Core ().V1 ().Pods (), sharedInformers .Batch ().V1 ().Jobs (), clientset )
@@ -6594,19 +6596,19 @@ func TestWatchOrphanPods(t *testing.T) {
6594
6596
sharedInformers .Batch ().V1 ().Jobs ().Informer ().GetIndexer ().Delete (tc .job )
6595
6597
})
6596
6598
}
6597
-
6599
+ _ , ctx := ktesting . NewTestContext ( t )
6598
6600
podBuilder := buildPod ().name (name ).deletionTimestamp ().trackingFinalizer ()
6599
6601
if tc .job != nil {
6600
6602
podBuilder = podBuilder .job (tc .job )
6601
6603
}
6602
6604
orphanPod := podBuilder .Pod
6603
- orphanPod , err := clientset .CoreV1 ().Pods ("default" ).Create (context . Background () , orphanPod , metav1.CreateOptions {})
6605
+ orphanPod , err := clientset .CoreV1 ().Pods ("default" ).Create (ctx , orphanPod , metav1.CreateOptions {})
6604
6606
if err != nil {
6605
6607
t .Fatalf ("Creating orphan pod: %v" , err )
6606
6608
}
6607
6609
6608
6610
if err := wait .PollUntilContextTimeout (ctx , 100 * time .Millisecond , wait .ForeverTestTimeout , false , func (ctx context.Context ) (bool , error ) {
6609
- p , err := clientset .CoreV1 ().Pods (orphanPod .Namespace ).Get (context . Background () , orphanPod .Name , metav1.GetOptions {})
6611
+ p , err := clientset .CoreV1 ().Pods (orphanPod .Namespace ).Get (ctx , orphanPod .Name , metav1.GetOptions {})
6610
6612
if err != nil {
6611
6613
return false , err
6612
6614
}
@@ -7610,7 +7612,7 @@ func TestFinalizersRemovedExpectations(t *testing.T) {
7610
7612
func TestFinalizerCleanup (t * testing.T ) {
7611
7613
_ , ctx := ktesting .NewTestContext (t )
7612
7614
ctx , cancel := context .WithCancel (ctx )
7613
- defer cancel ( )
7615
+ t . Cleanup ( cancel )
7614
7616
7615
7617
clientset := fake .NewClientset ()
7616
7618
sharedInformers := informers .NewSharedInformerFactory (clientset , controller .NoResyncPeriodFunc ())
0 commit comments