Skip to content

Commit

Permalink
Test healtz
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusfcr committed Dec 18, 2024
1 parent 767acf7 commit 225914b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions internal/http/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"strconv"
"sync"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -245,13 +246,32 @@ func TestIntegrationHttpMode(t *testing.T) {
resp agent.State
}

for {
res, err := http.Get(fmt.Sprintf("http://localhost:%d/healthcheck", *tt.args.config.Port))
if err == nil && res.StatusCode == 200 {
i := 0
for i < 5 {
res, err := http.Get(fmt.Sprintf("http://localhost:%d/healthz", *tt.args.config.Port))
if err != nil {
if errors.Is(err, syscall.ECONNREFUSED) {
l.Info("Connection refused - waiting...")
time.Sleep(1 * time.Second)
continue
}

t.Errorf("staring server: %v", err)
break
}
l.Info("Waiting for check to be ready")
time.Sleep(1 * time.Second)

if res.StatusCode != 200 {
t.Errorf("unexpected status for health: %v", res.StatusCode)
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
if string(body) != `"OK"` {
t.Errorf("unexpected status for health: %v", string(body))
}
break
}
if i == 5 {
t.Error("Unable to start the server")
}

// ch will receive the results of the concurrent job executions
Expand Down

0 comments on commit 225914b

Please sign in to comment.