Skip to content

Commit

Permalink
ClusterCacheTracker test should wait and close its reconciler
Browse files Browse the repository at this point in the history
Signed-off-by: Vince Prignano <vincepri@vmware.com>
  • Loading branch information
vincepri authored and sbueringer committed Oct 14, 2021
1 parent 8b2e29e commit 97b4a5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions controllers/remote/cluster_cache_tracker_test.go
Expand Up @@ -85,7 +85,7 @@ func TestClusterCacheTracker(t *testing.T) {
spew.Dump(err)
g.Expect(err).ToNot(HaveOccurred())
}()
<-env.Manager.Elected()
<-mgr.Elected()

k8sClient = mgr.GetClient()

Expand Down Expand Up @@ -119,11 +119,16 @@ func TestClusterCacheTracker(t *testing.T) {

teardown := func(t *testing.T, g *WithT, ns *corev1.Namespace) {
t.Helper()
defer close(c.ch)

t.Log("Deleting any Secrets")
g.Expect(cleanupTestSecrets(ctx, k8sClient)).To(Succeed())
t.Log("Deleting any Clusters")
g.Expect(cleanupTestClusters(ctx, k8sClient)).To(Succeed())
g.Expect(<-c.ch).To(Equal("mapped-" + clusterA.Name))
g.Consistently(func() int {
return len(c.ch)
}).Should(Equal(0))
t.Log("Deleting Namespace")
g.Expect(env.Delete(ctx, ns)).To(Succeed())
t.Log("Stopping the manager")
Expand Down Expand Up @@ -200,7 +205,11 @@ type testController struct {
}

func (c *testController) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
c.ch <- req.Name
spew.Dump(req)
select {
case <-ctx.Done():
case c.ch <- req.Name:
}
return ctrl.Result{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/envtest/environment.go
Expand Up @@ -274,7 +274,7 @@ func (e *Environment) start(ctx context.Context) {
panic(fmt.Sprintf("Failed to start the test environment manager: %v", err))
}
}()
e.Manager.Elected()
<-e.Manager.Elected()
e.WaitForWebhooks()
}

Expand Down

0 comments on commit 97b4a5f

Please sign in to comment.