mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Wait for cache to sync in job's TestWatchOrphanPods
Otherwise the event handler might not be called. Change-Id: I23c93c2251b411430a0f2469686db6355d84af2f
This commit is contained in:
parent
cc66198570
commit
a5f5eab5fd
@ -2591,21 +2591,17 @@ func TestWatchOrphanPods(t *testing.T) {
|
|||||||
manager.podStoreSynced = alwaysReady
|
manager.podStoreSynced = alwaysReady
|
||||||
manager.jobStoreSynced = alwaysReady
|
manager.jobStoreSynced = alwaysReady
|
||||||
|
|
||||||
jobSynced := false
|
|
||||||
manager.syncHandler = func(ctx context.Context, jobKey string) (bool, error) {
|
|
||||||
jobSynced = true
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
stopCh := make(chan struct{})
|
stopCh := make(chan struct{})
|
||||||
defer close(stopCh)
|
defer close(stopCh)
|
||||||
go sharedInformers.Core().V1().Pods().Informer().Run(stopCh)
|
podInformer := sharedInformers.Core().V1().Pods().Informer()
|
||||||
|
go podInformer.Run(stopCh)
|
||||||
|
cache.WaitForCacheSync(stopCh, podInformer.HasSynced)
|
||||||
go manager.Run(context.TODO(), 1)
|
go manager.Run(context.TODO(), 1)
|
||||||
|
|
||||||
// Create job but don't add it to the store.
|
// Create job but don't add it to the store.
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
job *batch.Job
|
job *batch.Job
|
||||||
inCache bool
|
inCache bool
|
||||||
wantJobSynced bool
|
|
||||||
}{
|
}{
|
||||||
"job_does_not_exist": {
|
"job_does_not_exist": {
|
||||||
job: newJob(2, 2, 6, batch.NonIndexedCompletion),
|
job: newJob(2, 2, 6, batch.NonIndexedCompletion),
|
||||||
@ -2625,9 +2621,13 @@ func TestWatchOrphanPods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for name, tc := range cases {
|
for name, tc := range cases {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
jobSynced = false
|
|
||||||
if tc.inCache {
|
if tc.inCache {
|
||||||
sharedInformers.Batch().V1().Jobs().Informer().GetIndexer().Add(tc.job)
|
if err := sharedInformers.Batch().V1().Jobs().Informer().GetIndexer().Add(tc.job); err != nil {
|
||||||
|
t.Fatalf("Failed to insert job in index: %v", err)
|
||||||
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
sharedInformers.Batch().V1().Jobs().Informer().GetIndexer().Delete(tc.job)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
podBuilder := buildPod().name(name).deletionTimestamp().trackingFinalizer()
|
podBuilder := buildPod().name(name).deletionTimestamp().trackingFinalizer()
|
||||||
@ -2649,9 +2649,6 @@ func TestWatchOrphanPods(t *testing.T) {
|
|||||||
}); err != nil {
|
}); err != nil {
|
||||||
t.Errorf("Waiting for Pod to get the finalizer removed: %v", err)
|
t.Errorf("Waiting for Pod to get the finalizer removed: %v", err)
|
||||||
}
|
}
|
||||||
if !tc.inCache && jobSynced {
|
|
||||||
t.Error("Tried to sync deleted job")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user