Skip to content

Commit

Permalink
fix(test): ping timeout check
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyong Huang <huangjy@emqx.io>
  • Loading branch information
ngjaying committed Oct 18, 2024
1 parent 1f0aab1 commit 52e5521
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions fvt/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net/http"
"path"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -470,7 +471,7 @@ func (s *ConnectionTestSuite) TestSinkPing() {
"measurement": "test",
},
timeout: true,
// err: "{\"error\":1000,\"message\":\"Get \\\"http://test.com/test/ping?parseTime=true&wait_for_leader=10s\\\": dial tcp 127.0.0.1:80: connectex: No connection could be made because the target machine actively refused it.\"}\n",
err: "{\"error\":1000,\"message\":\"Get \\\"http://test.com/test/ping?parseTime=true&wait_for_leader=10s\\\": dial tcp 127.0.0.1:80: connectex: No connection could be made because the target machine actively refused it.\"}\n",
},
{
name: "influx2",
Expand All @@ -482,7 +483,7 @@ func (s *ConnectionTestSuite) TestSinkPing() {
"measurement": "test",
},
timeout: true,
// err: "{\"error\":1000,\"message\":\"error connecting to influxdb2: Get \\\"http://root:***@test.com/ping\\\": dial tcp 127.0.0.1:80: connectex: No connection could be made because the target machine actively refused it.\"}\n",
err: "i/o timeout",
},
}
prefix := "metadata/sinks/connection"
Expand All @@ -492,15 +493,19 @@ func (s *ConnectionTestSuite) TestSinkPing() {
s.Require().NoError(err)
resp, err := client.Post(path.Join(prefix, tt.name), string(body))
if tt.timeout {
s.Require().Error(err)
if err != nil {
s.Require().Error(err)
return
}
}
s.Require().NoError(err)
if tt.err == "" {
s.Require().Equal(http.StatusOK, resp.StatusCode)
} else {
s.Require().Equal(http.StatusBadRequest, resp.StatusCode)
t, err := GetResponseText(resp)
s.Require().NoError(err)
if tt.err == "" {
s.Require().Equal(http.StatusOK, resp.StatusCode)
} else {
s.Require().Equal(http.StatusBadRequest, resp.StatusCode)
t, err := GetResponseText(resp)
s.Require().NoError(err)
if !strings.Contains(t, tt.err) {
s.Require().Equal(tt.err, t)
}
}
Expand Down
2 changes: 1 addition & 1 deletion fvt/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewSdk(baseUrl string) (*SDK, error) {
if err != nil {
return nil, err
}
return &SDK{baseUrl: u, httpClient: &http.Client{Timeout: 5 * time.Second}}, nil
return &SDK{baseUrl: u, httpClient: &http.Client{Timeout: 10 * time.Second}}, nil
}

func (sdk *SDK) Get(command string) (resp *http.Response, err error) {
Expand Down

0 comments on commit 52e5521

Please sign in to comment.