Skip to content

Commit 5a96630

Browse files
committed
Ensure caches are synchronized in reconciler tests
Caches are started asynchronously, and we should wait for them to be synchronized before proceeding with the test logic. In real execution, controller-runtime takes care of this for us, but in tests which only use the reconciler, we need to do it ourselves.
1 parent 922e7a1 commit 5a96630

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

controllers/reconcile_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ func createTestReconciler(t *testing.T, ctx context.Context, cfg config.Config)
13621362
require.NoError(t, err)
13631363
go func() {
13641364
startErr := runtimeCluster.Start(ctx)
1365-
require.NoError(t, startErr)
1365+
assert.NoError(t, startErr)
13661366
}()
13671367

13681368
cacheClient := runtimeCluster.GetClient()
@@ -1375,6 +1375,8 @@ func createTestReconciler(t *testing.T, ctx context.Context, cfg config.Config)
13751375
})
13761376
err = reconciler.SetupCaches(runtimeCluster)
13771377
require.NoError(t, err)
1378+
synced := runtimeCluster.GetCache().WaitForCacheSync(ctx)
1379+
require.True(t, synced, "caches didn't sync successfully")
13781380
return reconciler
13791381
}
13801382

0 commit comments

Comments
 (0)