Skip to content

Commit 983265a

Browse files
authored
Merge pull request kubernetes#94739 from knight42/fix/TestExpectationsOnRecreate
test: ensure WaitForCacheSync is called after starting sharedInformerFacotry
2 parents fd9828b + e89e72b commit 983265a

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

pkg/controller/daemon/daemon_controller_test.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,10 @@ func TestExpectationsOnRecreate(t *testing.T) {
521521
}
522522

523523
f.Start(stopCh)
524-
525-
cacheCtx, cancelCacheCtx := context.WithTimeout(context.Background(), 30*time.Second)
526-
defer cancelCacheCtx()
527-
ok := cache.WaitForNamedCacheSync(
528-
"test dsc",
529-
cacheCtx.Done(), f.Core().V1().Nodes().Informer().HasSynced,
530-
)
531-
if !ok {
532-
t.Fatal("caches failed to sync")
524+
for ty, ok := range f.WaitForCacheSync(stopCh) {
525+
if !ok {
526+
t.Fatalf("caches failed to sync: %v", ty)
527+
}
533528
}
534529

535530
expectStableQueueLength(0)
@@ -542,7 +537,7 @@ func TestExpectationsOnRecreate(t *testing.T) {
542537

543538
// create of DS adds to queue, processes
544539
waitForQueueLength(1, "created DS")
545-
ok = dsc.processNextWorkItem()
540+
ok := dsc.processNextWorkItem()
546541
if !ok {
547542
t.Fatal("queue is shutting down")
548543
}

pkg/controller/deployment/sync_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ func TestDeploymentController_cleanupDeployment(t *testing.T) {
428428
stopCh := make(chan struct{})
429429
defer close(stopCh)
430430
informers.Start(stopCh)
431+
informers.WaitForCacheSync(stopCh)
431432

432433
t.Logf(" &test.revisionHistoryLimit: %d", test.revisionHistoryLimit)
433434
d := newDeployment("foo", 1, &test.revisionHistoryLimit, nil, nil, map[string]string{"foo": "bar"})

pkg/controller/replicaset/replica_set_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"time"
3232

3333
apps "k8s.io/api/apps/v1"
34-
"k8s.io/api/core/v1"
34+
v1 "k8s.io/api/core/v1"
3535
apiequality "k8s.io/apimachinery/pkg/api/equality"
3636
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3737
"k8s.io/apimachinery/pkg/runtime"
@@ -599,6 +599,7 @@ func TestWatchControllers(t *testing.T) {
599599
BurstReplicas,
600600
)
601601
informers.Start(stopCh)
602+
informers.WaitForCacheSync(stopCh)
602603

603604
var testRSSpec apps.ReplicaSet
604605
received := make(chan string)
@@ -1151,6 +1152,7 @@ func TestExpectationsOnRecreate(t *testing.T) {
11511152
100,
11521153
)
11531154
f.Start(stopCh)
1155+
f.WaitForCacheSync(stopCh)
11541156
fakePodControl := controller.FakePodControl{}
11551157
manager.podControl = &fakePodControl
11561158

pkg/controller/volume/persistentvolume/pv_controller_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,12 @@ func TestControllerSync(t *testing.T) {
322322
// Start the controller
323323
stopCh := make(chan struct{})
324324
informers.Start(stopCh)
325+
informers.WaitForCacheSync(stopCh)
325326
go ctrl.Run(stopCh)
326327

327328
// Wait for the controller to pass initial sync and fill its caches.
328329
err = wait.Poll(10*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
329-
return ctrl.volumeListerSynced() &&
330-
ctrl.claimListerSynced() &&
331-
len(ctrl.claims.ListKeys()) >= len(test.initialClaims) &&
330+
return len(ctrl.claims.ListKeys()) >= len(test.initialClaims) &&
332331
len(ctrl.volumes.store.ListKeys()) >= len(test.initialVolumes), nil
333332
})
334333
if err != nil {

pkg/volume/csi/csi_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ func TestCSI_VolumeAll(t *testing.T) {
255255
csiDriverInformer.Informer().GetStore().Add(driverInfo)
256256
}
257257
factory.Start(wait.NeverStop)
258+
factory.WaitForCacheSync(wait.NeverStop)
258259

259260
host := volumetest.NewFakeVolumeHostWithCSINodeName(t,
260261
tmpDir,

0 commit comments

Comments
 (0)