Skip to content

Commit

Permalink
tests: divide all tests into the CI chunks including submodule tests (#…
Browse files Browse the repository at this point in the history
…6198)

ref #6181, ref #6183

Divide all tests into the CI chunks including submodule tests.

Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato authored Mar 24, 2023
1 parent 79ec29c commit c3934e4
Show file tree
Hide file tree
Showing 51 changed files with 118 additions and 103 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pd-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ jobs:
WORKER_ID: ${{ matrix.worker_id }}
WORKER_COUNT: 10
run: |
[ $WORKER_ID -ne $WORKER_COUNT ] && make ci-test-job JOB_COUNT=$(($WORKER_COUNT-1)) JOB_INDEX=$WORKER_ID
[ $WORKER_ID -eq $WORKER_COUNT ] && make ci-test-job-submod
make ci-test-job JOB_COUNT=$(($WORKER_COUNT)) JOB_INDEX=$WORKER_ID
mv covprofile covprofile_$WORKER_ID
sed -i "/failpoint_binding/d" covprofile_$WORKER_ID
- name: Upload coverage result ${{ matrix.worker_id }}
Expand Down
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,7 @@ basic-test: install-tools
ci-test-job: install-tools dashboard-ui
@$(FAILPOINT_ENABLE)
CGO_ENABLED=1 go test -timeout=15m -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=./... $(shell ./scripts/ci-subtask.sh $(JOB_COUNT) $(JOB_INDEX))
@$(FAILPOINT_DISABLE)

ci-test-job-submod: install-tools dashboard-ui
@$(FAILPOINT_ENABLE)
@ for mod in $(SUBMODULES); do cd $$mod && $(MAKE) ci-test-job && cd $(ROOT_PATH) > /dev/null && cat $$mod/covprofile >> covprofile; done
@$(FAILPOINT_DISABLE)
@ for mod in $(shell ./scripts/ci-subtask.sh $(JOB_COUNT) $(JOB_INDEX) 1); do cd $$mod && $(MAKE) ci-test-job && cd $(ROOT_PATH) > /dev/null && cat $$mod/covprofile >> covprofile; done

TSO_INTEGRATION_TEST_PKGS := $(PD_PKG)/tests/server/tso

Expand Down
6 changes: 3 additions & 3 deletions pd.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
},
{
"name": "pd-client-tests",
"path": "tests/client"
"path": "tests/integrations/client"
},
{
"name": "mcs-tests",
"path": "tests/mcs"
"path": "tests/integrations/mcs"
},
{
"name": "tso-tests",
"path": "tests/tso"
"path": "tests/integrations/tso"
},
{
"name": "pd-tso-bench",
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/grpcutil/grpcutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func TestToTLSConfig(t *testing.T) {
t.Parallel()
re := require.New(t)
tlsConfig := TLSConfig{
KeyPath: "../../../tests/client/cert/pd-server-key.pem",
CertPath: "../../../tests/client/cert/pd-server.pem",
CAPath: "../../../tests/client/cert/ca.pem",
KeyPath: "../../../tests/integrations/client/cert/pd-server-key.pem",
CertPath: "../../../tests/integrations/client/cert/pd-server.pem",
CAPath: "../../../tests/integrations/client/cert/ca.pem",
}
// test without bytes
_, err := tlsConfig.ToTLSConfig()
Expand Down
63 changes: 42 additions & 21 deletions scripts/ci-subtask.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
#!/bin/bash

# ./ci-subtask.sh <TOTAL_TASK_N> <TASK_INDEX>
# ./ci-subtask.sh <TOTAL_TASK_N> <TASK_INDEX> <INTEGRATION_TEST_ONLY>

packages=(`go list ./...`)
dirs=(`find . -iname "*_test.go" -exec dirname {} \; | sort -u | sed -e "s/^\./github.com\/tikv\/pd/"`)
tasks=($(comm -12 <(printf "%s\n" "${packages[@]}") <(printf "%s\n" "${dirs[@]}")))
if [[ $3 ]]; then
# Get integration test list.
makefile_dirs=($(find . -iname "Makefile" -exec dirname {} \; | sort -u))
submod_dirs=($(find . -iname "go.mod" -exec dirname {} \; | sort -u))
integration_tasks=$(comm -12 <(printf "%s\n" "${makefile_dirs[@]}") <(printf "%s\n" "${submod_dirs[@]}") | grep "./tests/integrations/*")
# Currently, we only have 3 integration tests, so we can hardcode the task index.
for t in ${integration_tasks[@]}; do
if [[ "$t" = "./tests/integrations/client" && "$2" = 9 ]]; then
printf "%s " "$t"
break
elif [[ "$t" = "./tests/integrations/tso" && "$2" = 7 ]]; then
printf "%s " "$t"
break
elif [[ "$t" = "./tests/integrations/mcs" && "$2" = 2 ]]; then
printf "%s " "$t"
break
fi
done
else
# Get package test list.
packages=($(go list ./...))
dirs=($(find . -iname "*_test.go" -exec dirname {} \; | sort -u | sed -e "s/^\./github.com\/tikv\/pd/"))
tasks=($(comm -12 <(printf "%s\n" "${packages[@]}") <(printf "%s\n" "${dirs[@]}")))

weight () {
[[ $1 == "github.com/tikv/pd/server/api" ]] && return 30
[[ $1 == "github.com/tikv/pd/pkg/schedule" ]] && return 30
[[ $1 =~ "pd/tests" ]] && return 5
return 1
}
weight() {
[[ $1 == "github.com/tikv/pd/server/api" ]] && return 30
[[ $1 == "github.com/tikv/pd/pkg/schedule" ]] && return 30
[[ $1 =~ "pd/tests" ]] && return 5
return 1
}

scores=(`seq "$1" | xargs -I{} echo 0`)
scores=($(seq "$1" | xargs -I{} echo 0))

res=()
for t in ${tasks[@]}; do
min_i=0
for i in ${!scores[@]}; do
[[ ${scores[i]} -lt ${scores[$min_i]} ]] && min_i=$i
res=()
for t in ${tasks[@]}; do
min_i=0
for i in ${!scores[@]}; do
[[ ${scores[i]} -lt ${scores[$min_i]} ]] && min_i=$i
done
weight $t
scores[$min_i]=$((${scores[$min_i]} + $?))
[[ $(($min_i + 1)) -eq $2 ]] && res+=($t)
done
weight $t
scores[$min_i]=$((${scores[$min_i]} + $?))
[[ $(($min_i+1)) -eq $2 ]] && res+=($t)
done

printf "%s " "${res[@]}"
printf "%s " "${res[@]}"
fi
28 changes: 13 additions & 15 deletions tests/client/Makefile → tests/integrations/client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,35 @@
# See the License for the specific language governing permissions and
# limitations under the License.

GO_TOOLS_BIN_PATH := $(shell pwd)/../../.tools/bin
ROOT_PATH := ../../..
GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin
PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

static: install-tools
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ golangci-lint run ./...
@ revive -formatter friendly -config ../../revive.toml .
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml .

tidy:
@ go mod tidy
git diff go.mod go.sum | cat
git diff --quiet go.mod go.sum

test: enable-codegen
CGO_ENABLED=1 go test -v -tags deadlock -race -cover || { $(MAKE) disable-codegen && exit 1; }
$(MAKE) disable-codegen
test: failpoint-enable
CGO_ENABLED=1 go test -v -tags deadlock -race -cover || { $(MAKE) failpoint-disable && exit 1; }
$(MAKE) failpoint-disable

basic-test:
# skip

ci-test-job: enable-codegen
CGO_ENABLED=1 go test -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=../../... github.com/tikv/pd/tests/client
ci-test-job:
CGO_ENABLED=1 go test -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=$(ROOT_PATH)/... github.com/tikv/pd/tests/integrations/client

install-tools:
cd ../../ && $(MAKE) install-tools
cd $(ROOT_PATH) && $(MAKE) install-tools

enable-codegen:
cd ../../ && $(MAKE) failpoint-enable
failpoint-enable:
cd $(ROOT_PATH) && $(MAKE) failpoint-enable
go mod tidy

disable-codegen:
cd ../../ && $(MAKE) failpoint-disable
failpoint-disable:
cd $(ROOT_PATH) && $(MAKE) failpoint-disable
go mod tidy
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions tests/client/go.mod → tests/integrations/client/go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module github.com/tikv/pd/tests/client
module github.com/tikv/pd/tests/integrations/client

go 1.20

replace (
github.com/tikv/pd => ../../../
github.com/tikv/pd/client => ../../../client
)

// reset grpc and protobuf deps in order to import client and server at the same time
replace google.golang.org/grpc v1.51.0 => google.golang.org/grpc v1.26.0

require (
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20230317010544-b47a4830141f
Expand Down Expand Up @@ -163,11 +171,3 @@ require (
moul.io/zapgorm2 v1.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace (
github.com/tikv/pd => ../../
github.com/tikv/pd/client => ../../client
)

// reset grpc and protobuf deps in order to import client and server at the same time
replace google.golang.org/grpc v1.51.0 => google.golang.org/grpc v1.26.0
File renamed without changes.
File renamed without changes.
25 changes: 13 additions & 12 deletions tests/mcs/Makefile → tests/integrations/mcs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@
# See the License for the specific language governing permissions and
# limitations under the License.

GO_TOOLS_BIN_PATH := $(shell pwd)/../../.tools/bin
ROOT_PATH := ../../..
GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin
PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

static: install-tools
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ golangci-lint run ./...
@ revive -formatter friendly -config ../../revive.toml .
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml .

tidy:
@ go mod tidy
git diff go.mod go.sum | cat
git diff --quiet go.mod go.sum

test: enable-codegen
CGO_ENABLED=1 go test ./... -tags deadlock -race -cover || { $(MAKE) disable-codegen && exit 1; }
$(MAKE) disable-codegen
test: failpoint-enable
CGO_ENABLED=1 go test ./... -v -tags deadlock -race -cover || { $(MAKE) failpoint-disable && exit 1; }
$(MAKE) failpoint-disable

ci-test-job: enable-codegen
CGO_ENABLED=1 go test ./... -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=../../... github.com/tikv/pd/tests/mcs
ci-test-job:
CGO_ENABLED=1 go test ./... -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=$(ROOT_PATH)/... github.com/tikv/pd/tests/integrations/mcs

install-tools:
cd ../../ && $(MAKE) install-tools
cd $(ROOT_PATH) && $(MAKE) install-tools

enable-codegen:
cd ../../ && $(MAKE) failpoint-enable
failpoint-enable:
cd $(ROOT_PATH) && $(MAKE) failpoint-enable
go mod tidy

disable-codegen:
cd ../../ && $(MAKE) failpoint-disable
failpoint-disable:
cd $(ROOT_PATH) && $(MAKE) failpoint-disable
go mod tidy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/tikv/pd/pkg/utils/tempurl"
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/tests"
"github.com/tikv/pd/tests/mcs"
"github.com/tikv/pd/tests/integrations/mcs"
"go.uber.org/goleak"
)

Expand Down
18 changes: 9 additions & 9 deletions tests/mcs/go.mod → tests/integrations/mcs/go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module github.com/tikv/pd/tests/mcs
module github.com/tikv/pd/tests/integrations/mcs

go 1.20

replace (
github.com/tikv/pd => ../../../
github.com/tikv/pd/client => ../../../client
)

// reset grpc and protobuf deps in order to import client and server at the same time
replace google.golang.org/grpc v1.51.0 => google.golang.org/grpc v1.26.0

require (
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20230317010544-b47a4830141f
Expand Down Expand Up @@ -163,11 +171,3 @@ require (
moul.io/zapgorm2 v1.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace (
github.com/tikv/pd => ../../
github.com/tikv/pd/client => ../../client
)

// reset grpc and protobuf deps in order to import client and server at the same time
replace google.golang.org/grpc v1.51.0 => google.golang.org/grpc v1.26.0
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/tikv/pd/client/grpcutil"
"github.com/tikv/pd/pkg/utils/tempurl"
"github.com/tikv/pd/tests"
"github.com/tikv/pd/tests/mcs"
"github.com/tikv/pd/tests/integrations/mcs"
)

func TestResourceManagerServer(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/pkg/utils/tsoutil"
"github.com/tikv/pd/tests"
"github.com/tikv/pd/tests/mcs"
"github.com/tikv/pd/tests/integrations/mcs"
"go.etcd.io/etcd/clientv3"
"go.uber.org/goleak"
"google.golang.org/grpc"
Expand Down
25 changes: 13 additions & 12 deletions tests/tso/Makefile → tests/integrations/tso/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@
# See the License for the specific language governing permissions and
# limitations under the License.

GO_TOOLS_BIN_PATH := $(shell pwd)/../../.tools/bin
ROOT_PATH := ../../..
GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin
PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)

static: install-tools
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }'
@ golangci-lint run ./...
@ revive -formatter friendly -config ../../revive.toml .
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml .

tidy:
@ go mod tidy
git diff go.mod go.sum | cat
git diff --quiet go.mod go.sum

test: enable-codegen
CGO_ENABLED=1 go test ./... -tags deadlock -race -cover || { $(MAKE) disable-codegen && exit 1; }
$(MAKE) disable-codegen
test: failpoint-enable
CGO_ENABLED=1 go test -v -tags deadlock -race -cover || { $(MAKE) failpoint-disable && exit 1; }
$(MAKE) failpoint-disable

ci-test-job: enable-codegen
CGO_ENABLED=1 go test ./... -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=../../... github.com/tikv/pd/tests/tso
ci-test-job:
CGO_ENABLED=1 go test -tags deadlock -race -covermode=atomic -coverprofile=covprofile -coverpkg=$(ROOT_PATH)/... github.com/tikv/pd/tests/integrations/tso

install-tools:
cd ../../ && $(MAKE) install-tools
cd $(ROOT_PATH) && $(MAKE) install-tools

enable-codegen:
cd ../../ && $(MAKE) failpoint-enable
failpoint-enable:
cd $(ROOT_PATH) && $(MAKE) failpoint-enable
go mod tidy

disable-codegen:
cd ../../ && $(MAKE) failpoint-disable
failpoint-disable:
cd $(ROOT_PATH) && $(MAKE) failpoint-disable
go mod tidy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/tikv/pd/pkg/utils/tempurl"
"github.com/tikv/pd/pkg/utils/tsoutil"
"github.com/tikv/pd/tests"
"github.com/tikv/pd/tests/mcs"
"github.com/tikv/pd/tests/integrations/mcs"
)

type tsoClientTestSuite struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
pd "github.com/tikv/pd/pkg/utils/testutil"
"github.com/tikv/pd/pkg/utils/tsoutil"
"github.com/tikv/pd/tests"
"github.com/tikv/pd/tests/mcs"
"github.com/tikv/pd/tests/integrations/mcs"
"google.golang.org/grpc"
)

Expand Down
Loading

0 comments on commit c3934e4

Please sign in to comment.