From e0af9298df4730105eecff4f392069019a69b9c1 Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Thu, 5 Dec 2024 13:36:17 +0100 Subject: [PATCH] Fix sporadic in probe tests (#193) --- .github/workflows/test.yml | 13 ------------- internal/probe/agent_test.go | 17 ----------------- internal/probe/probe_suite_test.go | 6 ++++++ internal/registry/registry_suite_test.go | 6 ++++++ 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index acc2ef5..93b84db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,20 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - - - name: Check if anything is using port 8080 and kill it - run: | - if lsof -i :8080; then - echo "Port 8080 is in use by:" - lsof -i :8080 - echo "Killing process using port 8080..." - kill -9 $(lsof -t -i :8080) - else - echo "Port 8080 is not in use." - fi - - run: make test 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..be574f3 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(registryURL) + 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()) })