diff --git a/quesma/quesma/quesma_test.go b/quesma/quesma/quesma_test.go index a44c6357a..83c2037b6 100644 --- a/quesma/quesma/quesma_test.go +++ b/quesma/quesma/quesma_test.go @@ -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) { @@ -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) + } + } +}