Skip to content

Commit ea488a0

Browse files
authored
Fix race condition in env test for service controller (#733)
1 parent 5a5f3ab commit ea488a0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/controller/service/controller_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,14 +660,11 @@ var _ = Describe("ServiceController", func() {
660660
})
661661

662662
It("should use CNAME target from Domain status for service hostname", func() {
663-
var cloudEndpoint *ngrokv1alpha1.CloudEndpoint
664-
665663
By("waiting for cloud endpoint to be created")
666664
Eventually(func(g Gomega) {
667665
cleps, err := getCloudEndpoints(k8sClient, namespace)
668666
g.Expect(err).NotTo(HaveOccurred())
669667
g.Expect(cleps.Items).To(HaveLen(1))
670-
cloudEndpoint = &cleps.Items[0]
671668
}, timeout, interval).Should(Succeed())
672669

673670
By("creating a Domain CRD with CNAME target in status")
@@ -697,10 +694,14 @@ var _ = Describe("ServiceController", func() {
697694

698695
By("updating the CloudEndpoint status with domainRef")
699696
Eventually(func(_ Gomega) error {
700-
fetchedClep := &ngrokv1alpha1.CloudEndpoint{}
701-
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(cloudEndpoint), fetchedClep); err != nil {
697+
cleps, err := getCloudEndpoints(k8sClient, namespace)
698+
if err != nil {
702699
return err
703700
}
701+
if len(cleps.Items) != 1 {
702+
return fmt.Errorf("expected 1 CloudEndpoint, got %d", len(cleps.Items))
703+
}
704+
fetchedClep := &cleps.Items[0]
704705
fetchedClep.Status.DomainRef = &ngrokv1alpha1.K8sObjectRefOptionalNamespace{
705706
Name: domainName,
706707
Namespace: ptr.To(namespace),

0 commit comments

Comments
 (0)