Skip to content

Commit

Permalink
Add the test suite
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Nov 6, 2023
1 parent 4cfac26 commit ed963c5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func NewClient(
}
c.pdAddrs = pdAddrs
// Init the HTTP client if it's not configured.
if c.cli != nil {
cli := &http.Client{Timeout: defaultTimeout}
if c.cli == nil {
c.cli = &http.Client{Timeout: defaultTimeout}
if c.tlsConf != nil {
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig = c.tlsConf
cli.Transport = transport
c.cli.Transport = transport

Check warning on line 102 in client/http/client.go

View check run for this annotation

Codecov / codecov/patch

client/http/client.go#L100-L102

Added lines #L100 - L102 were not covered by tests
}
}

Expand Down
73 changes: 73 additions & 0 deletions tests/integrations/client/http_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2023 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client_test

import (
"context"
"testing"

"github.com/stretchr/testify/suite"
pd "github.com/tikv/pd/client/http"
"github.com/tikv/pd/tests"
)

type httpClientTestSuite struct {
suite.Suite
ctx context.Context
cancelFunc context.CancelFunc
cluster *tests.TestCluster
client pd.Client
}

func TestHTTPClientTestSuite(t *testing.T) {
suite.Run(t, new(httpClientTestSuite))
}

func (suite *httpClientTestSuite) SetupSuite() {
re := suite.Require()
var err error
suite.ctx, suite.cancelFunc = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestCluster(suite.ctx, 1)
re.NoError(err)
err = suite.cluster.RunInitialServers()
re.NoError(err)
leader := suite.cluster.WaitLeader()
re.NotEmpty(leader)
err = suite.cluster.GetLeaderServer().BootstrapCluster()
re.NoError(err)
var (
testServers = suite.cluster.GetServers()
endpoints = make([]string, 0, len(testServers))
)
for _, s := range testServers {
endpoints = append(endpoints, s.GetConfig().AdvertiseClientUrls)
}
suite.client = pd.NewClient(endpoints)
}

func (suite *httpClientTestSuite) TearDownSuite() {
suite.cancelFunc()
suite.client.Close()
suite.cluster.Destroy()
}

func (suite *httpClientTestSuite) TestGetMinResolvedTSByStoresIDs() {
re := suite.Require()

minResolvedTS, storeMinResolvedTSMap, err := suite.client.GetMinResolvedTSByStoresIDs(suite.ctx, nil)
re.NoError(err)
re.Greater(minResolvedTS, uint64(0))
re.Empty(storeMinResolvedTSMap)
}

0 comments on commit ed963c5

Please sign in to comment.