From 2b8f6d67aabb3c5603b3cb60b22ad9419799fb82 Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Thu, 5 Dec 2024 13:18:19 +0100 Subject: [PATCH] Fix sporadic in probe tests --- internal/probe/agent_test.go | 17 ----------------- internal/probe/probe_suite_test.go | 6 ++++++ internal/registry/registry_suite_test.go | 6 ++++++ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/internal/probe/agent_test.go b/internal/probe/agent_test.go index a5d10a5..e11911d 100644 --- a/internal/probe/agent_test.go +++ b/internal/probe/agent_test.go @@ -4,13 +4,9 @@ package probe_test import ( - "context" "encoding/json" "fmt" "net/http" - "time" - - "github.com/ironcore-dev/metal-operator/internal/probe" "github.com/ironcore-dev/metal-operator/internal/api/registry" . "github.com/onsi/ginkgo/v2" @@ -18,19 +14,6 @@ import ( ) var _ = Describe("ProbeAgent", func() { - BeforeEach(func() { - By("Starting the probe agent") - ctx, cancel := context.WithCancel(context.Background()) - DeferCleanup(cancel) - - // Initialize your probe agent - probeAgent = probe.NewAgent(systemUUID, registryURL, 100*time.Millisecond) - go func() { - defer GinkgoRecover() - Expect(probeAgent.Start(ctx)).To(Succeed(), "failed to start probe agent") - }() - }) - It("should ensure the correct endpoints have been registered", func() { By("performing a GET request to the /systems/{uuid} endpoint") var resp *http.Response diff --git a/internal/probe/probe_suite_test.go b/internal/probe/probe_suite_test.go index 70a74c0..814ab3e 100644 --- a/internal/probe/probe_suite_test.go +++ b/internal/probe/probe_suite_test.go @@ -5,6 +5,7 @@ package probe_test import ( "context" + "net/http" "testing" "time" @@ -43,6 +44,11 @@ var _ = BeforeSuite(func() { Expect(registryServer.Start(ctx)).To(Succeed(), "failed to start registry agent") }() + Eventually(func() error { + _, err := http.Get(registryAddr) + return err + }).Should(Succeed()) + // Initialize your probe server probeAgent = probe.NewAgent(systemUUID, registryURL, 100*time.Millisecond) go func() { diff --git a/internal/registry/registry_suite_test.go b/internal/registry/registry_suite_test.go index be1fcbb..65abda6 100644 --- a/internal/registry/registry_suite_test.go +++ b/internal/registry/registry_suite_test.go @@ -5,6 +5,7 @@ package registry_test import ( "context" + "net/http" "testing" "github.com/ironcore-dev/metal-operator/internal/registry" @@ -36,4 +37,9 @@ var _ = BeforeSuite(func() { defer GinkgoRecover() Expect(server.Start(ctx)).To(Succeed(), "failed to start registry server") }() + + Eventually(func() error { + _, err := http.Get(testServerURL) + return err + }).Should(Succeed()) })