Skip to content

Commit bd1f86a

Browse files
authored
Merge pull request kubernetes#125914 from mimowo/cleanup-job-tests
Cleanup Job tests: align error messages, no TODO ctx, no unused params
2 parents 6432b3d + 4250d44 commit bd1f86a

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

pkg/controller/job/job_controller_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,7 +5287,7 @@ func TestSyncJobUpdateRequeue(t *testing.T) {
52875287
job := newJob(2, 2, 6, batch.NonIndexedCompletion)
52885288
sharedInformerFactory.Batch().V1().Jobs().Informer().GetIndexer().Add(job)
52895289
manager.queue.Add(testutil.GetKey(job, t))
5290-
manager.processNextWorkItem(context.TODO())
5290+
manager.processNextWorkItem(ctx)
52915291
if tc.wantRequeued {
52925292
verifyEmptyQueueAndAwaitForQueueLen(ctx, t, manager, 1)
52935293
} else {
@@ -5297,7 +5297,7 @@ func TestSyncJobUpdateRequeue(t *testing.T) {
52975297
// into the queue asynchronously.
52985298
manager.clock.Sleep(fastJobApiBackoff)
52995299
time.Sleep(time.Millisecond)
5300-
verifyEmptyQueue(ctx, t, manager)
5300+
verifyEmptyQueue(t, manager)
53015301
}
53025302
})
53035303
}
@@ -5570,7 +5570,7 @@ func TestGetPodsForJob(t *testing.T) {
55705570
informer.Core().V1().Pods().Informer().GetIndexer().Add(p)
55715571
}
55725572

5573-
pods, err := jm.getPodsForJob(context.TODO(), job)
5573+
pods, err := jm.getPodsForJob(ctx, job)
55745574
if err != nil {
55755575
t.Fatalf("getPodsForJob() error: %v", err)
55765576
}
@@ -5961,7 +5961,7 @@ func TestWatchJobs(t *testing.T) {
59615961
stopCh := make(chan struct{})
59625962
defer close(stopCh)
59635963
sharedInformerFactory.Start(stopCh)
5964-
go manager.Run(context.TODO(), 1)
5964+
go manager.Run(ctx, 1)
59655965

59665966
// We're sending new job to see if it reaches syncHandler.
59675967
testJob.Namespace = "bar"
@@ -6008,7 +6008,7 @@ func TestWatchPods(t *testing.T) {
60086008
stopCh := make(chan struct{})
60096009
defer close(stopCh)
60106010
go sharedInformerFactory.Core().V1().Pods().Informer().Run(stopCh)
6011-
go manager.Run(context.TODO(), 1)
6011+
go manager.Run(ctx, 1)
60126012

60136013
pods := newPodList(1, v1.PodRunning, testJob)
60146014
testPod := pods[0]
@@ -6035,7 +6035,7 @@ func TestWatchOrphanPods(t *testing.T) {
60356035
podInformer := sharedInformers.Core().V1().Pods().Informer()
60366036
go podInformer.Run(stopCh)
60376037
cache.WaitForCacheSync(stopCh, podInformer.HasSynced)
6038-
go manager.Run(context.TODO(), 1)
6038+
go manager.Run(ctx, 1)
60396039

60406040
// Create job but don't add it to the store.
60416041
cases := map[string]struct {
@@ -6297,7 +6297,7 @@ func TestJobApiBackoffReset(t *testing.T) {
62976297
// error returned make the key requeued
62986298
fakePodControl.Err = errors.New("Controller error")
62996299
manager.queue.Add(key)
6300-
manager.processNextWorkItem(context.TODO())
6300+
manager.processNextWorkItem(ctx)
63016301
retries := manager.queue.NumRequeues(key)
63026302
if retries != 1 {
63036303
t.Fatalf("%s: expected exactly 1 retry, got %d", job.Name, retries)
@@ -6307,8 +6307,8 @@ func TestJobApiBackoffReset(t *testing.T) {
63076307

63086308
// the queue is emptied on success
63096309
fakePodControl.Err = nil
6310-
manager.processNextWorkItem(context.TODO())
6311-
verifyEmptyQueue(ctx, t, manager)
6310+
manager.processNextWorkItem(ctx)
6311+
verifyEmptyQueue(t, manager)
63126312
}
63136313

63146314
var _ workqueue.TypedRateLimitingInterface[string] = &fakeRateLimitingQueue{}
@@ -7091,13 +7091,13 @@ func podReplacementPolicy(m batch.PodReplacementPolicy) *batch.PodReplacementPol
70917091

70927092
func verifyEmptyQueueAndAwaitForQueueLen(ctx context.Context, t *testing.T, jm *Controller, wantQueueLen int) {
70937093
t.Helper()
7094-
verifyEmptyQueue(ctx, t, jm)
7094+
verifyEmptyQueue(t, jm)
70957095
awaitForQueueLen(ctx, t, jm, wantQueueLen)
70967096
}
70977097

70987098
func awaitForQueueLen(ctx context.Context, t *testing.T, jm *Controller, wantQueueLen int) {
70997099
t.Helper()
7100-
verifyEmptyQueue(ctx, t, jm)
7100+
verifyEmptyQueue(t, jm)
71017101
if err := wait.PollUntilContextTimeout(ctx, fastRequeue, time.Second, true, func(ctx context.Context) (bool, error) {
71027102
if requeued := jm.queue.Len() == wantQueueLen; requeued {
71037103
return true, nil
@@ -7109,7 +7109,7 @@ func awaitForQueueLen(ctx context.Context, t *testing.T, jm *Controller, wantQue
71097109
}
71107110
}
71117111

7112-
func verifyEmptyQueue(ctx context.Context, t *testing.T, jm *Controller) {
7112+
func verifyEmptyQueue(t *testing.T, jm *Controller) {
71137113
t.Helper()
71147114
if jm.queue.Len() > 0 {
71157115
t.Errorf("Unexpected queue.Len(). Want: %d, got: %d", 0, jm.queue.Len())

0 commit comments

Comments
 (0)