Skip to content

Commit

Permalink
ci: putting tools tests in a separate chunk (#7800)
Browse files Browse the repository at this point in the history
close #7805

Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Feb 6, 2024
1 parent ddf810b commit 0419004
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pd-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
env:
WORKER_ID: ${{ matrix.worker_id }}
WORKER_COUNT: 13
JOB_COUNT: 10 # 11, 12, 13 are for other integrations jobs
JOB_COUNT: 9 # 10 is tools test, 11, 12, 13 are for other integrations jobs
run: |
make ci-test-job JOB_COUNT=$(($JOB_COUNT)) JOB_INDEX=$WORKER_ID
mv covprofile covprofile_$WORKER_ID
Expand Down
13 changes: 9 additions & 4 deletions scripts/ci-subtask.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/bin/bash
#!/usr/bin/env bash

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

ROOT_PATH=../../

if [[ $2 -gt 10 ]]; then
if [[ $2 -gt 9 ]]; then
# run tools tests
if [[ $2 -eq 10 ]]; then
cd ./tools && make ci-test-job && cd .. && cat ./covprofile >> covprofile || exit 1
exit
fi

# Currently, we only have 3 integration tests, so we can hardcode the task index.
integrations_dir=./tests/integrations
integrations_tasks=($(find "$integrations_dir" -mindepth 1 -maxdepth 1 -type d))
# Currently, we only have 3 integration tests, so we can hardcode the task index.
for t in "${integrations_tasks[@]}"; do
if [[ "$t" = "$integrations_dir/client" && $2 -eq 11 ]]; then
cd ./client && make ci-test-job && cd .. && cat ./covprofile >> covprofile || exit 1
Expand All @@ -29,7 +35,6 @@ else
[[ $1 == "github.com/tikv/pd/pkg/schedule" ]] && return 30
[[ $1 == "github.com/tikv/pd/pkg/core" ]] && return 30
[[ $1 == "github.com/tikv/pd/tests/server/api" ]] && return 30
[[ $1 == "github.com/tikv/pd/tools" ]] && return 30
[[ $1 =~ "pd/tests" ]] && return 5
return 1
}
Expand Down
2 changes: 0 additions & 2 deletions tests/integrations/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ install-tools:

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

failpoint-disable:
cd $(ROOT_PATH) && $(MAKE) failpoint-disable
go mod tidy
10 changes: 10 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ tidy:
@ go mod tidy
git diff go.mod go.sum | cat
git diff --quiet go.mod go.sum

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

failpoint-enable:
cd $(ROOT_PATH) && $(MAKE) failpoint-enable

failpoint-disable:
cd $(ROOT_PATH) && $(MAKE) failpoint-disable
5 changes: 4 additions & 1 deletion tools/pd-ctl/tests/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func TestConfigTestSuite(t *testing.T) {
suite.Run(t, new(configTestSuite))
}

func (suite *configTestSuite) SetupSuite() {
func (suite *configTestSuite) SetupTest() {
// use a new environment to avoid affecting other tests
suite.env = pdTests.NewSchedulingTestEnvironment(suite.T())
}

Expand All @@ -96,6 +97,7 @@ func (suite *configTestSuite) TearDownTest() {
re.NoError(err)
}
suite.env.RunFuncInTwoModes(cleanFunc)
suite.env.Cleanup()
}

func (suite *configTestSuite) TestConfig() {
Expand Down Expand Up @@ -877,6 +879,7 @@ func TestReplicationMode(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-ctl/tests/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ func TestHealth(t *testing.T) {
defer cancel()
tc, err := pdTests.NewTestCluster(ctx, 3)
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
tc.WaitLeader()
leaderServer := tc.GetLeaderServer()
re.NoError(leaderServer.BootstrapCluster())
pdAddr := tc.GetConfig().GetClientURL()
cmd := ctl.GetRootCmd()
defer tc.Destroy()

client := tc.GetEtcdClient()
members, err := cluster.GetMembers(client)
Expand Down
2 changes: 2 additions & 0 deletions tools/pd-ctl/tests/hot/hot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func TestHistoryHotRegions(t *testing.T) {
},
)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down Expand Up @@ -521,6 +522,7 @@ func TestBuckets(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1, func(cfg *config.Config, serverName string) { cfg.Schedule.HotRegionCacheHitsThreshold = 0 })
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down
8 changes: 8 additions & 0 deletions tools/pd-ctl/tests/keyspace/keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestKeyspaceGroup(t *testing.T) {
defer cancel()
tc, err := pdTests.NewTestAPICluster(ctx, 1)
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
tc.WaitLeader()
Expand Down Expand Up @@ -103,6 +104,7 @@ func TestSplitKeyspaceGroup(t *testing.T) {
conf.Keyspace.PreAlloc = keyspaces
})
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down Expand Up @@ -157,6 +159,7 @@ func TestExternalAllocNodeWhenStart(t *testing.T) {
conf.Keyspace.PreAlloc = keyspaces
})
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down Expand Up @@ -196,6 +199,7 @@ func TestSetNodeAndPriorityKeyspaceGroup(t *testing.T) {
conf.Keyspace.PreAlloc = keyspaces
})
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down Expand Up @@ -299,6 +303,7 @@ func TestMergeKeyspaceGroup(t *testing.T) {
conf.Keyspace.PreAlloc = keyspaces
})
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down Expand Up @@ -417,6 +422,7 @@ func TestKeyspaceGroupState(t *testing.T) {
conf.Keyspace.PreAlloc = keyspaces
})
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down Expand Up @@ -507,6 +513,7 @@ func TestShowKeyspaceGroupPrimary(t *testing.T) {
conf.Keyspace.PreAlloc = keyspaces
})
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down Expand Up @@ -594,6 +601,7 @@ func TestInPDMode(t *testing.T) {
defer cancel()
tc, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down
8 changes: 7 additions & 1 deletion tools/pd-ctl/tests/keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestKeyspace(t *testing.T) {
conf.Keyspace.PreAlloc = keyspaces
})
re.NoError(err)
defer tc.Destroy()
err = tc.RunInitialServers()
re.NoError(err)
pdAddr := tc.GetConfig().GetClientURL()
Expand Down Expand Up @@ -115,6 +116,7 @@ func TestKeyspaceGroupUninitialized(t *testing.T) {
re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/keyspace/skipSplitRegion", "return(true)"))
tc, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer tc.Destroy()
re.NoError(tc.RunInitialServers())
tc.WaitLeader()
re.NoError(tc.GetLeaderServer().BootstrapCluster())
Expand Down Expand Up @@ -165,10 +167,14 @@ func (suite *keyspaceTestSuite) TearDownTest() {
re := suite.Require()
re.NoError(failpoint.Disable("github.com/tikv/pd/server/delayStartServerLoop"))
re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/keyspace/skipSplitRegion"))
}

func (suite *keyspaceTestSuite) TearDownSuite() {
suite.cancel()
suite.cluster.Destroy()
}

func (suite *keyspaceTestSuite) TestshowKeyspace() {
func (suite *keyspaceTestSuite) TestShowKeyspace() {
re := suite.Require()
keyspaceName := "DEFAULT"
keyspaceID := uint32(0)
Expand Down
1 change: 1 addition & 0 deletions tools/pd-ctl/tests/label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestLabel(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1, func(cfg *config.Config, serverName string) { cfg.Replication.StrictlyMatchLabel = false })
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down
1 change: 1 addition & 0 deletions tools/pd-ctl/tests/member/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestMember(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 3)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down
14 changes: 7 additions & 7 deletions tools/pd-ctl/tests/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,25 @@ func (suite *operatorTestSuite) checkOperator(cluster *pdTests.TestCluster) {
})
}

output, err = tests.ExecuteCommand(cmd, "operator", "add", "transfer-region", "1", "2", "3")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "add", "transfer-region", "1", "2", "3")
re.NoError(err)
re.Contains(string(output), "not supported")
output, err = tests.ExecuteCommand(cmd, "operator", "add", "transfer-region", "1", "2", "follower", "3")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "add", "transfer-region", "1", "2", "follower", "3")
re.NoError(err)
re.Contains(string(output), "not match")
output, err = tests.ExecuteCommand(cmd, "operator", "add", "transfer-peer", "1", "2", "4")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "add", "transfer-peer", "1", "2", "4")
re.NoError(err)
re.Contains(string(output), "is unhealthy")
output, err = tests.ExecuteCommand(cmd, "operator", "add", "transfer-region", "1", "2", "leader", "4", "follower")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "add", "transfer-region", "1", "2", "leader", "4", "follower")
re.NoError(err)
re.Contains(string(output), "is unhealthy")
output, err = tests.ExecuteCommand(cmd, "operator", "add", "transfer-region", "1", "2", "follower", "leader", "3", "follower")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "add", "transfer-region", "1", "2", "follower", "leader", "3", "follower")
re.NoError(err)
re.Contains(string(output), "invalid")
output, err = tests.ExecuteCommand(cmd, "operator", "add", "transfer-region", "1", "leader", "2", "follower", "3")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "add", "transfer-region", "1", "leader", "2", "follower", "3")
re.NoError(err)
re.Contains(string(output), "invalid")
output, err = tests.ExecuteCommand(cmd, "operator", "add", "transfer-region", "1", "2", "leader", "3", "follower")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "add", "transfer-region", "1", "2", "leader", "3", "follower")
re.NoError(err)
re.Contains(string(output), "Success!")
output, err = tests.ExecuteCommand(cmd, "-u", pdAddr, "operator", "remove", "1")
Expand Down
3 changes: 3 additions & 0 deletions tools/pd-ctl/tests/region/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestRegionKeyFormat(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
defer cluster.Destroy()
re.NoError(err)
err = cluster.RunInitialServers()
re.NoError(err)
Expand All @@ -62,6 +63,7 @@ func TestRegion(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down Expand Up @@ -216,6 +218,7 @@ func TestRegionNoLeader(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down
20 changes: 10 additions & 10 deletions tools/pd-ctl/tests/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestSchedulerTestSuite(t *testing.T) {
func (suite *schedulerTestSuite) SetupSuite() {
re := suite.Require()
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/skipStoreConfigSync", `return(true)`))
suite.env = pdTests.NewSchedulingTestEnvironment(suite.T())
suite.defaultSchedulers = []string{
"balance-leader-scheduler",
"balance-region-scheduler",
Expand All @@ -59,6 +58,11 @@ func (suite *schedulerTestSuite) SetupSuite() {
}
}

func (suite *schedulerTestSuite) SetupTest() {
// use a new environment to avoid affecting other tests
suite.env = pdTests.NewSchedulingTestEnvironment(suite.T())
}

func (suite *schedulerTestSuite) TearDownSuite() {
re := suite.Require()
suite.env.Cleanup()
Expand Down Expand Up @@ -91,13 +95,11 @@ func (suite *schedulerTestSuite) TearDownTest() {
}
}
suite.env.RunFuncInTwoModes(cleanFunc)
suite.env.Cleanup()
}

func (suite *schedulerTestSuite) TestScheduler() {
// use a new environment to avoid affecting other tests
env := pdTests.NewSchedulingTestEnvironment(suite.T())
env.RunTestInTwoModes(suite.checkScheduler)
env.Cleanup()
suite.env.RunTestInTwoModes(suite.checkScheduler)
}

func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
Expand Down Expand Up @@ -483,7 +485,8 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
pdTests.MustPutStore(re, cluster, store)
}
re.Equal("5.2.0", leaderServer.GetClusterVersion().String())
// After upgrading, we should not use query.
// After upgrading, we can use query.
expected1["write-leader-priorities"] = []any{"query", "byte"}
checkHotSchedulerConfig(expected1)
// cannot set qps as write-peer-priorities
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", "balance-hot-region-scheduler", "set", "write-peer-priorities", "query,byte"}, nil)
Expand Down Expand Up @@ -636,10 +639,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
}

func (suite *schedulerTestSuite) TestSchedulerDiagnostic() {
// use a new environment to avoid affecting other tests
env := pdTests.NewSchedulingTestEnvironment(suite.T())
env.RunTestInTwoModes(suite.checkSchedulerDiagnostic)
env.Cleanup()
suite.env.RunTestInTwoModes(suite.checkSchedulerDiagnostic)
}

func (suite *schedulerTestSuite) checkSchedulerDiagnostic(cluster *pdTests.TestCluster) {
Expand Down
3 changes: 3 additions & 0 deletions tools/pd-ctl/tests/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestStore(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down Expand Up @@ -492,6 +493,7 @@ func TestTombstoneStore(t *testing.T) {
defer cancel()
cluster, err := pdTests.NewTestCluster(ctx, 1)
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down Expand Up @@ -592,6 +594,7 @@ func TestStoreTLS(t *testing.T) {
conf.InitialCluster = strings.ReplaceAll(conf.InitialCluster, "http", "https")
})
re.NoError(err)
defer cluster.Destroy()
err = cluster.RunInitialServers()
re.NoError(err)
cluster.WaitLeader()
Expand Down
14 changes: 13 additions & 1 deletion tools/pd-ctl/tests/tso/tso_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestTSO(t *testing.T) {

// tso command
ts := "395181938313123110"
args := []string{"-u", "127.0.0.1", "tso", ts}
args := []string{"tso", ts}
output, err := tests.ExecuteCommand(cmd, args...)
re.NoError(err)
tsTime, err := strconv.ParseUint(ts, 10, 64)
Expand All @@ -46,4 +46,16 @@ func TestTSO(t *testing.T) {
physicalTime := time.Unix(int64(physical/1000), int64(physical%1000)*time.Millisecond.Nanoseconds())
str := fmt.Sprintln("system: ", physicalTime) + fmt.Sprintln("logic: ", logicalTime)
re.Equal(string(output), str)

// test with invalid address
args = []string{"-u", "127.0.0.1", "tso", ts}
output, err = tests.ExecuteCommand(cmd, args...)
re.NoError(err)
tsTime, err = strconv.ParseUint(ts, 10, 64)
re.NoError(err)
logicalTime = tsTime & logicalBits
physical = tsTime >> physicalShiftBits
physicalTime = time.Unix(int64(physical/1000), int64(physical%1000)*time.Millisecond.Nanoseconds())
str = fmt.Sprintln("system: ", physicalTime) + fmt.Sprintln("logic: ", logicalTime)
re.Equal(string(output), str)
}
Loading

0 comments on commit 0419004

Please sign in to comment.