diff --git a/internal/test/envtest/environment.go b/internal/test/envtest/environment.go index 8441e4e8bfe5..2727ff1f7b68 100644 --- a/internal/test/envtest/environment.go +++ b/internal/test/envtest/environment.go @@ -26,7 +26,6 @@ import ( goruntime "runtime" "strconv" "strings" - "sync" "testing" "time" @@ -71,32 +70,26 @@ import ( "sigs.k8s.io/cluster-api/webhooks" ) -var once sync.Once - func init() { - once.Do(func() { - logger := klog.Background() - // Use klog as the internal logger for this envtest environment. - log.SetLogger(logger) - // Additionally force all controllers to use the Ginkgo logger. - ctrl.SetLogger(logger) - // Add logger for ginkgo. - klog.SetOutput(ginkgo.GinkgoWriter) - // Use the writer that klog sets to write. - klog.LogToStderr(false) - - // Calculate the scheme. - utilruntime.Must(apiextensionsv1.AddToScheme(scheme.Scheme)) - utilruntime.Must(admissionv1.AddToScheme(scheme.Scheme)) - utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme)) - utilruntime.Must(bootstrapv1.AddToScheme(scheme.Scheme)) - utilruntime.Must(expv1.AddToScheme(scheme.Scheme)) - utilruntime.Must(addonsv1.AddToScheme(scheme.Scheme)) - utilruntime.Must(controlplanev1.AddToScheme(scheme.Scheme)) - utilruntime.Must(admissionv1.AddToScheme(scheme.Scheme)) - utilruntime.Must(runtimev1.AddToScheme(scheme.Scheme)) - utilruntime.Must(ipamv1.AddToScheme(scheme.Scheme)) - }) + logger := klog.Background() + // Use klog as the internal logger for this envtest environment. + log.SetLogger(logger) + // Additionally force all controllers to use the Ginkgo logger. + ctrl.SetLogger(logger) + // Add logger for ginkgo. + klog.SetOutput(ginkgo.GinkgoWriter) + + // Calculate the scheme. + utilruntime.Must(apiextensionsv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(admissionv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(bootstrapv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(expv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(addonsv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(controlplanev1.AddToScheme(scheme.Scheme)) + utilruntime.Must(admissionv1.AddToScheme(scheme.Scheme)) + utilruntime.Must(runtimev1.AddToScheme(scheme.Scheme)) + utilruntime.Must(ipamv1.AddToScheme(scheme.Scheme)) } // RunInput is the input for Run. diff --git a/test/infrastructure/inmemory/pkg/runtime/cache/sync.go b/test/infrastructure/inmemory/pkg/runtime/cache/sync.go index c05ff75b5dfe..e731cff1b7e4 100644 --- a/test/infrastructure/inmemory/pkg/runtime/cache/sync.go +++ b/test/infrastructure/inmemory/pkg/runtime/cache/sync.go @@ -50,8 +50,10 @@ func (c *cache) startSyncer(ctx context.Context) error { c.syncQueue.ShutDown() }() + syncLoopStarted := make(chan struct{}) go func() { log.Info("Starting sync loop") + syncLoopStarted <- struct{}{} for { select { case <-time.After(c.syncPeriod / 4): @@ -79,6 +81,8 @@ func (c *cache) startSyncer(ctx context.Context) error { wg.Wait() }() + <-syncLoopStarted + if err := wait.PollUntilContextTimeout(ctx, 50*time.Millisecond, 5*time.Second, false, func(context.Context) (done bool, err error) { if atomic.LoadInt64(&workers) < int64(c.syncConcurrency) { return false, nil