Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Aug 14, 2023
1 parent 411dd12 commit 667d1ba
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions server/api/min_resolved_ts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
package api

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"reflect"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -133,7 +131,7 @@ func (suite *minResolvedTSTestSuite) TestMinResolvedTSByStores() {
rc := suite.svr.GetRaftCluster()
ts := uint64(233)

// set all stores min resolved ts.
// scope is `cluster`
testStoresID := make([]string, 0)
testMap := make(map[uint64]uint64)
for i := 1; i <= suite.storesNum; i++ {
Expand All @@ -149,17 +147,27 @@ func (suite *minResolvedTSTestSuite) TestMinResolvedTSByStores() {
IsRealTime: true,
PersistInterval: interval,
StoresMinResolvedTS: testMap,
}, testStoresID)
}, "cluster")

// set all stores min resolved ts.
testStoresIDStr := strings.Join(testStoresID, ",")
suite.checkMinResolvedTSByStores(&minResolvedTS{
MinResolvedTS: 234,
IsRealTime: true,
PersistInterval: interval,
StoresMinResolvedTS: testMap,
}, testStoresIDStr)

// remove last store for test.
testStoresID = testStoresID[:len(testStoresID)-1]
testStoresIDStr = strings.Join(testStoresID, ",")
delete(testMap, uint64(suite.storesNum))
suite.checkMinResolvedTSByStores(&minResolvedTS{
MinResolvedTS: 234,
IsRealTime: true,
PersistInterval: interval,
StoresMinResolvedTS: testMap,
}, testStoresID)
}, testStoresIDStr)
}

func (suite *minResolvedTSTestSuite) setMinResolvedTSPersistenceInterval(duration typeutil.Duration) {
Expand All @@ -183,15 +191,15 @@ func (suite *minResolvedTSTestSuite) checkMinResolvedTS(expect *minResolvedTS) {
listResp := &minResolvedTS{}
err = apiutil.ReadJSON(res.Body, listResp)
suite.NoError(err)
suite.Nil(listResp.StoresMinResolvedTS)
return reflect.DeepEqual(expect, listResp)
}, time.Second*10, time.Millisecond*20)
}

func (suite *minResolvedTSTestSuite) checkMinResolvedTSByStores(expect *minResolvedTS, storeIDs []string) {
func (suite *minResolvedTSTestSuite) checkMinResolvedTSByStores(expect *minResolvedTS, scope string) {
suite.Eventually(func() bool {
data, _ := json.Marshal(storeIDs)
req, _ := http.NewRequest(http.MethodGet, suite.url, bytes.NewBuffer(data))
res, err := testDialClient.Do(req)
url := fmt.Sprintf("%s?scope=%s", suite.url, scope)
res, err := testDialClient.Get(url)
suite.NoError(err)
defer res.Body.Close()
listResp := &minResolvedTS{}
Expand Down

0 comments on commit 667d1ba

Please sign in to comment.