Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/ut: accelerate the build process and scatter test #8342

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions .github/workflows/pd-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ jobs:
- worker_id: 2
name: 'Unit Test(2)'
- worker_id: 3
name: 'Tools Test'
name: 'Unit Test(3)'
- worker_id: 4
name: 'Client Integration Test'
name: 'Tests(1)'
- worker_id: 5
name: 'TSO Integration Test'
name: 'Tests(2)'
- worker_id: 6
name: 'MicroService Integration Test'
name: 'Tools Test'
- worker_id: 7
name: 'Client Integration Test'
- worker_id: 8
name: 'TSO Integration Test'
- worker_id: 9
name: 'MicroService Integration(!TSO)'
- worker_id: 10
name: 'MicroService Integration(TSO)'
outputs:
job-total: 6
job-total: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -52,6 +60,9 @@ jobs:
run: |
make ci-test-job JOB_INDEX=$WORKER_ID
mv covprofile covprofile_$WORKER_ID
if [ -f junitfile ]; then
cat junitfile
fi
- name: Upload coverage result ${{ matrix.worker_id }}
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ docs/swagger/*
*.before
covprofile
coverage.tmp
junitfile
package.list
report.xml
coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ failpoint-disable: install-tools
ut: pd-ut
@$(FAILPOINT_ENABLE)
# only run unit tests
./bin/pd-ut run --ignore tests --race
./bin/pd-ut run --ignore tests --race --junitfile ./junitfile
@$(CLEAN_UT_BINARY)
@$(FAILPOINT_DISABLE)

Expand Down
2 changes: 1 addition & 1 deletion pkg/core/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ func BenchmarkRandomSetRegion(b *testing.B) {

func TestGetRegionSizeByRange(t *testing.T) {
regions := NewRegionsInfo()
nums := 1000010
nums := 100001
for i := 0; i < nums; i++ {
peer := &metapb.Peer{StoreId: 1, Id: uint64(i + 1)}
endKey := []byte(fmt.Sprintf("%20d", i+1))
Expand Down
39 changes: 28 additions & 11 deletions scripts/ci-subtask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,51 @@
# ./ci-subtask.sh <TOTAL_TASK_N> <TASK_INDEX>

ROOT_PATH_COV=$(pwd)/covprofile
ROOT_PATH_JUNITFILE=$(pwd)/junitfile
# Currently, we only have 3 integration tests, so we can hardcode the task index.
integrations_dir=$(pwd)/tests/integrations

case $1 in
1)
# unit tests ignore `tests`
./bin/pd-ut run --race --ignore tests --coverprofile $ROOT_PATH_COV || exit 1
# unit tests ignore `tests`, `server`, `schedule`,`utils` and `encryption`
./bin/pd-ut run --ignore tests,server,pkg/schedule,pkg/utils,pkg/encryption --race --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if these packages are deleted or renamed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be necessary to manually change the code,when noticing abnormal test time/test codecov

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • codev can reveal missing tests
  • Redundant tests can be reacted to at test time

;;
2)
# unit tests only in `tests`
./bin/pd-ut run tests --race --coverprofile $ROOT_PATH_COV || exit 1
# unit tests only in `schedule` and `encryption` without `tests`
./bin/pd-ut run schedule,encryption --ignore tests --race --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
;;
3)
# unit tests only in `server` and `utils` without `tests`
./bin/pd-ut run server,utils --ignore tests --race --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
;;
4)
# tests only in `tests` without `server/api, server/cluster and `server/config`
./bin/pd-ut run tests --ignore tests/server/api,tests/server/cluster,tests/server/config --race --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
;;
5)
# tests only in `server/api, server/cluster and `server/config` in `tests`
./bin/pd-ut run tests/server/api,tests/server/cluster,tests/server/config --race --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
;;
6)
# tools tests
cd ./tools && make ci-test-job && cat covprofile >> $ROOT_PATH_COV || exit 1
;;
4)
7)
# integration test client
./bin/pd-ut it run client --race --coverprofile $ROOT_PATH_COV || exit 1
./bin/pd-ut it run client --race --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
# client tests
cd ./client && make ci-test-job && cat covprofile >> $ROOT_PATH_COV || exit 1
;;
5)
8)
# integration test tso
./bin/pd-ut it run tso --race --coverprofile $ROOT_PATH_COV || exit 1
./bin/pd-ut it run tso --race --ignore mcs/tso --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
;;
6)
# integration test mcs
./bin/pd-ut it run mcs --race --coverprofile $ROOT_PATH_COV || exit 1
9)
# integration test mcs without mcs/tso
./bin/pd-ut it run mcs --race --ignore mcs/tso --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
;;
10)
# integration test mcs/tso
./bin/pd-ut it run mcs/tso --race --coverprofile $ROOT_PATH_COV --junitfile $ROOT_PATH_JUNITFILE || exit 1
;;
esac
2 changes: 1 addition & 1 deletion server/api/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func TestRegionsWithKillRequest(t *testing.T) {
url := fmt.Sprintf("%s%s/api/v1/regions", addr, apiPrefix)
mustBootstrapCluster(re, svr)

regionCount := 100000
regionCount := 10000
tu.GenerateTestDataConcurrently(regionCount, func(i int) {
r := core.NewTestRegionInfo(uint64(i+2), 1,
[]byte(fmt.Sprintf("%09d", i)),
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestLeaderTransferAndMoveCluster(t *testing.T) {
}()

// Transfer leader.
for i := 0; i < 5; i++ {
for i := 0; i < 3; i++ {
oldLeaderName := cluster.WaitLeader()
err := cluster.GetServer(oldLeaderName).ResignLeader()
re.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/scheduling/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func (suite *apiTestSuite) checkAdminRegionCacheForward(cluster *tests.TestClust
}

func (suite *apiTestSuite) TestFollowerForward() {
suite.env.RunTestInTwoModes(suite.checkFollowerForward)
suite.env.RunTestBasedOnMode(suite.checkFollowerForward)
}

func (suite *apiTestSuite) checkFollowerForward(cluster *tests.TestCluster) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/tso/keyspace_group_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (suite *tsoKeyspaceGroupManagerTestSuite) allocID() uint32 {
return uint32(id)
}

func TestTSOKeyspaceGroupManager(t *testing.T) {
func TestTSOKeyspaceGroupManagerSuite(t *testing.T) {
suite.Run(t, &tsoKeyspaceGroupManagerTestSuite{})
}

Expand Down
72 changes: 42 additions & 30 deletions tests/integrations/mcs/tso/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func TestWaitAPIServiceReady(t *testing.T) {
}
}

type APIServerForwardTestSuite struct {
suite.Suite
type APIServerForward struct {
re *require.Assertions
ctx context.Context
cancel context.CancelFunc
cluster *tests.TestCluster
Expand All @@ -270,13 +270,11 @@ type APIServerForwardTestSuite struct {
pdClient pd.Client
}

func TestAPIServerForwardTestSuite(t *testing.T) {
suite.Run(t, new(APIServerForwardTestSuite))
}

func (suite *APIServerForwardTestSuite) SetupTest() {
func NewAPIServerForward(re *require.Assertions) APIServerForward {
suite := APIServerForward{
re: re,
}
var err error
re := suite.Require()
suite.ctx, suite.cancel = context.WithCancel(context.Background())
suite.cluster, err = tests.NewTestAPICluster(suite.ctx, 3)
re.NoError(err)
Expand All @@ -294,11 +292,12 @@ func (suite *APIServerForwardTestSuite) SetupTest() {
suite.pdClient, err = pd.NewClientWithContext(context.Background(),
[]string{suite.backendEndpoints}, pd.SecurityOption{}, pd.WithMaxErrorRetry(1))
re.NoError(err)
return suite
}

func (suite *APIServerForwardTestSuite) TearDownTest() {
re := suite.Require()
func (suite *APIServerForward) ShutDown() {
suite.pdClient.Close()
re := suite.re

etcdClient := suite.pdLeader.GetEtcdClient()
clusterID := strconv.FormatUint(suite.pdLeader.GetClusterID(), 10)
Expand All @@ -314,8 +313,10 @@ func (suite *APIServerForwardTestSuite) TearDownTest() {
re.NoError(failpoint.Disable("github.com/tikv/pd/client/usePDServiceMode"))
}

func (suite *APIServerForwardTestSuite) TestForwardTSORelated() {
re := suite.Require()
func TestForwardTSORelated(t *testing.T) {
re := require.New(t)
suite := NewAPIServerForward(re)
defer suite.ShutDown()
// Unable to use the tso-related interface without tso server
suite.checkUnavailableTSO(re)
tc, err := tests.NewTestTSOCluster(suite.ctx, 1, suite.backendEndpoints)
Expand All @@ -325,8 +326,10 @@ func (suite *APIServerForwardTestSuite) TestForwardTSORelated() {
suite.checkAvailableTSO(re)
}

func (suite *APIServerForwardTestSuite) TestForwardTSOWhenPrimaryChanged() {
re := suite.Require()
func TestForwardTSOWhenPrimaryChanged(t *testing.T) {
re := require.New(t)
suite := NewAPIServerForward(re)
defer suite.ShutDown()

tc, err := tests.NewTestTSOCluster(suite.ctx, 2, suite.backendEndpoints)
re.NoError(err)
Expand Down Expand Up @@ -363,10 +366,11 @@ func (suite *APIServerForwardTestSuite) TestForwardTSOWhenPrimaryChanged() {
suite.checkAvailableTSO(re)
}

func (suite *APIServerForwardTestSuite) TestResignTSOPrimaryForward() {
func TestResignTSOPrimaryForward(t *testing.T) {
re := require.New(t)
suite := NewAPIServerForward(re)
defer suite.ShutDown()
// TODO: test random kill primary with 3 nodes
re := suite.Require()

tc, err := tests.NewTestTSOCluster(suite.ctx, 2, suite.backendEndpoints)
re.NoError(err)
defer tc.Destroy()
Expand All @@ -388,8 +392,10 @@ func (suite *APIServerForwardTestSuite) TestResignTSOPrimaryForward() {
}
}

func (suite *APIServerForwardTestSuite) TestResignAPIPrimaryForward() {
re := suite.Require()
func TestResignAPIPrimaryForward(t *testing.T) {
re := require.New(t)
suite := NewAPIServerForward(re)
defer suite.ShutDown()

tc, err := tests.NewTestTSOCluster(suite.ctx, 2, suite.backendEndpoints)
re.NoError(err)
Expand All @@ -410,8 +416,10 @@ func (suite *APIServerForwardTestSuite) TestResignAPIPrimaryForward() {
}
}

func (suite *APIServerForwardTestSuite) TestForwardTSOUnexpectedToFollower1() {
re := suite.Require()
func TestForwardTSOUnexpectedToFollower1(t *testing.T) {
re := require.New(t)
suite := NewAPIServerForward(re)
defer suite.ShutDown()
suite.checkForwardTSOUnexpectedToFollower(func() {
// unary call will retry internally
// try to update gc safe point
Expand All @@ -421,8 +429,10 @@ func (suite *APIServerForwardTestSuite) TestForwardTSOUnexpectedToFollower1() {
})
}

func (suite *APIServerForwardTestSuite) TestForwardTSOUnexpectedToFollower2() {
re := suite.Require()
func TestForwardTSOUnexpectedToFollower2(t *testing.T) {
re := require.New(t)
suite := NewAPIServerForward(re)
defer suite.ShutDown()
suite.checkForwardTSOUnexpectedToFollower(func() {
// unary call will retry internally
// try to set external ts
Expand All @@ -433,16 +443,18 @@ func (suite *APIServerForwardTestSuite) TestForwardTSOUnexpectedToFollower2() {
})
}

func (suite *APIServerForwardTestSuite) TestForwardTSOUnexpectedToFollower3() {
re := suite.Require()
func TestForwardTSOUnexpectedToFollower3(t *testing.T) {
re := require.New(t)
suite := NewAPIServerForward(re)
defer suite.ShutDown()
suite.checkForwardTSOUnexpectedToFollower(func() {
_, _, err := suite.pdClient.GetTS(suite.ctx)
re.Error(err)
})
}

func (suite *APIServerForwardTestSuite) checkForwardTSOUnexpectedToFollower(checkTSO func()) {
re := suite.Require()
func (suite *APIServerForward) checkForwardTSOUnexpectedToFollower(checkTSO func()) {
re := suite.re
tc, err := tests.NewTestTSOCluster(suite.ctx, 2, suite.backendEndpoints)
re.NoError(err)
tc.WaitForDefaultPrimaryServing(re)
Expand Down Expand Up @@ -477,7 +489,7 @@ func (suite *APIServerForwardTestSuite) checkForwardTSOUnexpectedToFollower(chec
tc.Destroy()
}

func (suite *APIServerForwardTestSuite) addRegions() {
func (suite *APIServerForward) addRegions() {
leader := suite.cluster.GetServer(suite.cluster.WaitLeader())
rc := leader.GetServer().GetRaftCluster()
for i := 0; i < 3; i++ {
Expand All @@ -491,7 +503,7 @@ func (suite *APIServerForwardTestSuite) addRegions() {
}
}

func (suite *APIServerForwardTestSuite) checkUnavailableTSO(re *require.Assertions) {
func (suite *APIServerForward) checkUnavailableTSO(re *require.Assertions) {
_, _, err := suite.pdClient.GetTS(suite.ctx)
re.Error(err)
// try to update gc safe point
Expand All @@ -502,7 +514,7 @@ func (suite *APIServerForwardTestSuite) checkUnavailableTSO(re *require.Assertio
re.Error(err)
}

func (suite *APIServerForwardTestSuite) checkAvailableTSO(re *require.Assertions) {
func (suite *APIServerForward) checkAvailableTSO(re *require.Assertions) {
mcs.WaitForTSOServiceAvailable(suite.ctx, re, suite.pdClient)
// try to get ts
_, _, err := suite.pdClient.GetTS(suite.ctx)
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ func (suite *tsoClientTestSuite) getBackendEndpoints() []string {
return strings.Split(suite.backendEndpoints, ",")
}

func TestLegacyTSOClient(t *testing.T) {
func TestLegacyTSOClientSuite(t *testing.T) {
suite.Run(t, &tsoClientTestSuite{
legacy: true,
})
}

func TestMicroserviceTSOClient(t *testing.T) {
func TestMicroserviceTSOClientSuite(t *testing.T) {
suite.Run(t, &tsoClientTestSuite{
legacy: false,
})
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/tso/consistency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ type tsoConsistencyTestSuite struct {
tsoClient tsopb.TSOClient
}

func TestLegacyTSOConsistency(t *testing.T) {
func TestLegacyTSOConsistencySuite(t *testing.T) {
suite.Run(t, &tsoConsistencyTestSuite{
legacy: true,
})
}

func TestMicroserviceTSOConsistency(t *testing.T) {
func TestMicroserviceTSOConsistencySuite(t *testing.T) {
suite.Run(t, &tsoConsistencyTestSuite{
legacy: false,
})
Expand Down
2 changes: 1 addition & 1 deletion tests/server/api/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (suite *checkerTestSuite) TearDownSuite() {
}

func (suite *checkerTestSuite) TestAPI() {
suite.env.RunTestInTwoModes(suite.checkAPI)
suite.env.RunTestBasedOnMode(suite.checkAPI)
}

func (suite *checkerTestSuite) checkAPI(cluster *tests.TestCluster) {
Expand Down
Loading
Loading