From cb5c06c718c326ca9e1a9fd31c7e3cf6e47175a8 Mon Sep 17 00:00:00 2001 From: PowderLi <135960789+PowderLi@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:22:50 +0800 Subject: [PATCH] fix: wait server to listen the http port (#29075) issue: #29068 wait server to listen the http port then check whether various urls can be accessed normally Signed-off-by: PowderLi --- internal/http/server_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/http/server_test.go b/internal/http/server_test.go index 852353dfd3..cc838d6921 100644 --- a/internal/http/server_test.go +++ b/internal/http/server_test.go @@ -22,10 +22,12 @@ import ( "encoding/json" "fmt" "io" + "net" "net/http" "os" "strings" "testing" + "time" "github.com/stretchr/testify/suite" "go.uber.org/zap" @@ -43,6 +45,13 @@ type HTTPServerTestSuite struct { func (suite *HTTPServerTestSuite) SetupSuite() { paramtable.Init() ServeHTTP() + conn, err := net.DialTimeout("tcp", "localhost:"+DefaultListenPort, time.Second*5) + if err != nil { + time.Sleep(time.Second) + conn, err = net.DialTimeout("tcp", "localhost:"+DefaultListenPort, time.Second*5) + } + suite.Equal(nil, err) + conn.Close() } func (suite *HTTPServerTestSuite) TearDownSuite() {