Skip to content

Commit

Permalink
wait for healthy quesma (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
pivovarit authored May 7, 2024
1 parent b13632a commit 24d5a52
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions quesma/quesma/quesma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package quesma

import (
"context"
"fmt"
"github.com/stretchr/testify/assert"
"mitmproxy/quesma/quesma/config"
"mitmproxy/quesma/telemetry"
"mitmproxy/quesma/tracing"
"net/http"
"testing"
"time"
)

func TestShouldExposePprof(t *testing.T) {
Expand All @@ -19,13 +21,35 @@ func TestShouldExposePprof(t *testing.T) {
Elasticsearch: config.ElasticsearchConfiguration{Url: &config.Url{}},
}, make(<-chan tracing.LogWithLevel), false)
quesma.Start()
waitForHealthyQuesma(t)
t.Cleanup(func() {
quesma.Close(context.Background())
})
response, err := http.Get("http://localhost:9999/debug/pprof/")
if err != nil {

t.Fatal("could not reach /debug/pprof:", err)
}

assert.Equal(t, 200, response.StatusCode)
}

func waitForHealthyQuesma(t *testing.T) {
for i := 0; i < 10; i++ {
resp, err := http.Get("http://localhost:9999/_quesma/health")
if err != nil {
fmt.Println("Error, retrying:", err)
time.Sleep(1 * time.Second)
continue
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
return
}

if i == 9 {
t.Fatal("quesma failed healthcheck", err)
}
}
}

0 comments on commit 24d5a52

Please sign in to comment.