Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Nov 8, 2023
1 parent ab8bf7b commit 46026e4
Show file tree
Hide file tree
Showing 33 changed files with 1,314 additions and 25 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/real_tiup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PD Real TiUP Test
on:
push:
branches:
- master
- release-*
pull_request:
branches:
- master
- release-*
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
real-cluster:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.21'
- name: Checkout code
uses: actions/checkout@v3
- name: Restore cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
**/.tools
**/.dashboard_download_cache
key: ${{ runner.os }}-go-${{ matrix.worker_id }}-${{ hashFiles('**/go.sum') }}

- name: Test
run: make check
working-directory: tests/integrations/realtiup
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ ifeq ($(PLUGIN), 1)
BUILD_TAGS += with_plugin
endif

LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDReleaseVersion=$(shell git describe --tags --dirty --always)"
RELEASE_VERSION ?= $(shell git describe --tags --dirty --always)
ifeq ($(RUN_CI), 1)
RELEASE_VERSION := None
endif

LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDReleaseVersion=$(RELEASE_VERSION)"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDBuildTS=$(shell date -u '+%Y-%m-%d %I:%M:%S')"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDGitHash=$(shell git rev-parse HEAD)"
LDFLAGS += -X "$(PD_PKG)/pkg/versioninfo.PDGitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
Expand Down
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type GlobalConfigItem struct {
PayLoad []byte
}

// Client is a PD (Placement Driver) client.
// Client is a PD (Placement Driver) RPC client.
// It should not be used after calling Close().
type Client interface {
// GetClusterID gets the cluster ID from PD.
Expand Down Expand Up @@ -512,7 +512,7 @@ func newClientWithKeyspaceName(
return nil
}

// Create a PD service discovery with null keyspace id, then query the real id wth the keyspace name,
// Create a PD service discovery with null keyspace id, then query the realtiup id wth the keyspace name,
// finally update the keyspace id to the PD service discovery for the following interactions.
c.pdSvcDiscovery = newPDServiceDiscovery(
clientCtx, clientCancel, &c.wg, c.setServiceMode, updateKeyspaceIDCb, nullKeyspaceID, c.svrUrls, c.tlsCfg, c.option)
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func (c *client) ScanRegions(ctx context.Context, key, endKey []byte, limit int)
defer span.Finish()
}
start := time.Now()
defer cmdDurationScanRegions.Observe(time.Since(start).Seconds())
defer func() { cmdDurationScanRegions.Observe(time.Since(start).Seconds()) }()

var cancel context.CancelFunc
scanCtx := ctx
Expand Down
71 changes: 71 additions & 0 deletions client/http/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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 http

import (
"fmt"
"net/url"
)

// The following constants are the paths of PD HTTP APIs.
const (
HotRead = "/pd/api/v1/hotspot/regions/read"
HotWrite = "/pd/api/v1/hotspot/regions/write"
Regions = "/pd/api/v1/regions"
regionByID = "/pd/api/v1/region/id"
regionByKey = "/pd/api/v1/region/key"
regionsByKey = "/pd/api/v1/regions/key"
regionsByStoreID = "/pd/api/v1/regions/store"
Stores = "/pd/api/v1/stores"
Store = "/pd/api/v1/store"

MinResolvedTSPrefix = "/pd/api/v1/min-resolved-ts"

Leader = "/pd/api/v1/leader"
TransferLeader = "/pd/api/v1/leader/transfer"

Schedulers = "/pd/api/v1/schedulers"
)

// RegionByID returns the path of PD HTTP API to get region by ID.
func RegionByID(regionID uint64) string {
return fmt.Sprintf("%s/%d", regionByID, regionID)

Check warning on line 44 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L44

Added line #L44 was not covered by tests
}

// RegionByKey returns the path of PD HTTP API to get region by key.
func RegionByKey(key []byte) string {
return fmt.Sprintf("%s/%s", regionByKey, url.QueryEscape(string(key)))

Check warning on line 49 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L49

Added line #L49 was not covered by tests
}

// RegionsByKey returns the path of PD HTTP API to scan regions with given start key, end key and limit parameters.
func RegionsByKey(startKey, endKey []byte, limit int) string {
return fmt.Sprintf("%s?start_key=%s&end_key=%s&limit=%d",
regionsByKey, url.QueryEscape(string(startKey)), url.QueryEscape(string(endKey)), limit)

Check warning on line 55 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L54-L55

Added lines #L54 - L55 were not covered by tests
}

// RegionsByStoreID returns the path of PD HTTP API to get regions by store ID.
func RegionsByStoreID(storeID uint64) string {
return fmt.Sprintf("%s/%d", regionsByStoreID, storeID)

Check warning on line 60 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L60

Added line #L60 was not covered by tests
}

// LabelByStore returns the path of PD HTTP API to set store label.
func LabelByStore(storeID int64) string {
return fmt.Sprintf("%s/%d/label", Store, storeID)

Check warning on line 65 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L65

Added line #L65 was not covered by tests
}

// TransferLeaderID returns the path of PD HTTP API to transfer leader by ID.
func TransferLeaderID(leaderID string) string {
return fmt.Sprintf("%s/%s", TransferLeader, leaderID)

Check warning on line 70 in client/http/api.go

View check run for this annotation

Codecov / codecov/patch

client/http/api.go#L70

Added line #L70 was not covered by tests
}
Loading

0 comments on commit 46026e4

Please sign in to comment.