Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

dmctl: use dmctl binary directly in integration test #135

Merged
merged 34 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ff84050
dmctl: use dmctl binary directly in integration test
amyangfei May 6, 2019
eabad88
wip
amyangfei May 7, 2019
369bc47
refactor some dmctl package
amyangfei May 7, 2019
5fba533
add new test case for dmctl test
amyangfei May 7, 2019
3dd17f4
add query-status test
amyangfei May 7, 2019
94de8f1
add check_task api test
amyangfei May 8, 2019
a42f06a
add pause/resume relay test
amyangfei May 8, 2019
bb36bf5
addd pause/resume task test
amyangfei May 9, 2019
f76514d
reinfe some dmctl test case
amyangfei May 9, 2019
ced194c
add show-ddl-locks test
amyangfei May 9, 2019
24df0b6
add show-ddl-locks retry
amyangfei May 9, 2019
87cb270
add update-relay test
amyangfei May 9, 2019
c145c41
wip
amyangfei May 9, 2019
9d2f5ce
fix update relay
amyangfei May 14, 2019
ea0a2e9
more update-relay test
amyangfei May 14, 2019
d4ec7f5
Merge branch 'master' into add-dmctl-test
amyangfei May 14, 2019
0a3e298
remove comment for usage_and_arg_test
amyangfei May 14, 2019
bc5b1c0
add update task test
amyangfei May 14, 2019
f815b05
Merge branch 'master' into add-dmctl-test
amyangfei May 14, 2019
12a5a9b
fix update-task test
amyangfei May 14, 2019
cbc3340
add update-master-config test
amyangfei May 14, 2019
bf927cf
add update-master-config success test
amyangfei May 14, 2019
9ed25e1
add purge-relay test
amyangfei May 16, 2019
5bd4fc4
add more dmctl test cases
amyangfei May 16, 2019
6e9b3c7
add more dmctl tests
amyangfei May 16, 2019
b29b0b2
address comment. remove stop_relay.go, update test function name
amyangfei May 20, 2019
839ac7a
address comment, remove duplicated function
amyangfei May 20, 2019
c8efc05
address comment, fix some test function name
amyangfei May 20, 2019
36b6ca9
address comment, fix some useless worker parameter
amyangfei May 20, 2019
5e21b50
Merge branch 'master' into add-dmctl-test
amyangfei May 20, 2019
5f86167
Merge branch 'master' into add-dmctl-test
amyangfei May 20, 2019
0f2d856
address comment, revert master/sql_operation.go update
amyangfei May 21, 2019
dffc301
Merge branch 'master' into add-dmctl-test
amyangfei May 22, 2019
94b1eab
Merge branch 'master' into add-dmctl-test
amyangfei May 22, 2019
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ dm_integration_test_build:
-coverpkg=github.com/pingcap/dm/... \
-o bin/dm-master.test github.com/pingcap/dm/cmd/dm-master \
|| { $(FAILPOINT_DISABLE); exit 1; }
$(GOTEST) -c -race -cover -covermode=atomic \
-coverpkg=github.com/pingcap/dm/... \
-o bin/dmctl.test github.com/pingcap/dm/cmd/dm-ctl \
|| { $(FAILPOINT_DISABLE); exit 1; }
$(GOTEST) -c -race -cover -covermode=atomic \
-coverpkg=github.com/pingcap/dm/... \
-o bin/dm-tracer.test github.com/pingcap/dm/cmd/dm-tracer \
Expand Down
28 changes: 16 additions & 12 deletions tests/dmctl_tools/dmctl_start_task.go → cmd/dm-ctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@

package main

// Reference: https://dzone.com/articles/measuring-integration-test-coverage-rate-in-pouchc

import (
"context"
"os"

"github.com/pingcap/dm/tests/utils"
"strings"
"testing"
)

func main() {
cli, err := utils.CreateDmCtl("127.0.0.1:8261")
if err != nil {
utils.ExitWithError(err)
}
conf := os.Args[1]
err = utils.StartTask(context.Background(), cli, conf, nil)
if err != nil {
utils.ExitWithError(err)
func TestRunMain(t *testing.T) {
var args []string
for _, arg := range os.Args {
switch {
case arg == "DEVEL":
case strings.HasPrefix(arg, "-test."):
default:
args = append(args, arg)
}
}

os.Args = args
main()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package master
package common

import (
"context"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// operateRelay does operation on relay unit
func operateRelay(op pb.RelayOp, workers []string) (*pb.OperateWorkerRelayResponse, error) {
// OperateRelay does operation on relay unit
func OperateRelay(op pb.RelayOp, workers []string) (*pb.OperateWorkerRelayResponse, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli := common.MasterClient()
cli := MasterClient()
return cli.OperateWorkerRelayTask(ctx, &pb.OperateWorkerRelayRequest{
Op: op,
Workers: workers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package master
package common

import (
"context"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// operateTask does operation on task
func operateTask(op pb.TaskOp, name string, workers []string) (*pb.OperateTaskResponse, error) {
// OperateTask does operation on task
func OperateTask(op pb.TaskOp, name string, workers []string) (*pb.OperateTaskResponse, error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli := common.MasterClient()
cli := MasterClient()
return cli.OperateTask(ctx, &pb.OperateTaskRequest{
Op: op,
Name: name,
Expand Down
2 changes: 1 addition & 1 deletion dm/ctl/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func Start(args []string) {
master.NewSwitchRelayMasterCmd(),
master.NewPauseRelayCmd(),
master.NewResumeRelayCmd(),
//master.NewStopRelayCmd(),
master.NewUpdateMasterConfigCmd(),
master.NewUpdateRelayCmd(),
master.NewPurgeRelayCmd(),
master.NewMigrateRelayCmd(),
)

rootCmd.SetArgs(args)
Expand Down
7 changes: 4 additions & 3 deletions dm/ctl/master/pause_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package master
import (
"fmt"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// NewPauseRelayCmd creates a PauseRelay command
Expand Down Expand Up @@ -49,7 +50,7 @@ func pauseRelayFunc(cmd *cobra.Command, _ []string) {
return
}

resp, err := operateRelay(pb.RelayOp_PauseRelay, workers)
resp, err := common.OperateRelay(pb.RelayOp_PauseRelay, workers)
if err != nil {
common.PrintLines("can not pause relay unit:\n%v", errors.ErrorStack(err))
return
Expand Down
7 changes: 4 additions & 3 deletions dm/ctl/master/pause_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package master
import (
"fmt"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// NewPauseTaskCmd creates a PauseTask command
Expand All @@ -46,7 +47,7 @@ func pauseTaskFunc(cmd *cobra.Command, _ []string) {
return
}

resp, err := operateTask(pb.TaskOp_Pause, name, workers)
resp, err := common.OperateTask(pb.TaskOp_Pause, name, workers)
if err != nil {
common.PrintLines("can not pause task %s:\n%v", name, errors.ErrorStack(err))
return
Expand Down
7 changes: 4 additions & 3 deletions dm/ctl/master/resume_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package master
import (
"fmt"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// NewResumeRelayCmd creates a ResumeRelay command
Expand Down Expand Up @@ -49,7 +50,7 @@ func resumeRelayFunc(cmd *cobra.Command, _ []string) {
return
}

resp, err := operateRelay(pb.RelayOp_ResumeRelay, workers)
resp, err := common.OperateRelay(pb.RelayOp_ResumeRelay, workers)
if err != nil {
common.PrintLines("can not resume relay unit:\n%v", errors.ErrorStack(err))
return
Expand Down
7 changes: 4 additions & 3 deletions dm/ctl/master/resume_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package master
import (
"fmt"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// NewResumeTaskCmd creates a ResumeTask command
Expand All @@ -46,7 +47,7 @@ func resumeTaskFunc(cmd *cobra.Command, _ []string) {
return
}

resp, err := operateTask(pb.TaskOp_Resume, name, workers)
resp, err := common.OperateTask(pb.TaskOp_Resume, name, workers)
if err != nil {
common.PrintLines("can not resume task %s:\n%v", name, errors.ErrorStack(err))
return
Expand Down
5 changes: 3 additions & 2 deletions dm/ctl/master/sql_skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"fmt"
"strings"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// NewSQLSkipCmd creates a SQLSkip command
Expand Down
59 changes: 0 additions & 59 deletions dm/ctl/master/stop_relay.go

This file was deleted.

7 changes: 4 additions & 3 deletions dm/ctl/master/stop_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ package master
import (
"fmt"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/dm/pb"
)

// NewStopTaskCmd creates a StopTask command
Expand All @@ -46,7 +47,7 @@ func stopTaskFunc(cmd *cobra.Command, _ []string) {
return
}

resp, err := operateTask(pb.TaskOp_Stop, name, workers)
resp, err := common.OperateTask(pb.TaskOp_Stop, name, workers)
if err != nil {
common.PrintLines("can not stop task %s:\n%v", name, errors.ErrorStack(err))
return
Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Several convenient commands are provided:

* `run_dm_master <WORKDIR> <PORT> <CONFIG>` — Starts `dm-master` using config provided, on given port, running in workdir.
* `run_dm_worker <WORKDIR> <PORT> <CONFIG>` — Starts `dm-worker` using config provided, on given port, running in workdir.
* `run_dm_ctl <WORKDIR> <MASTER_ADDR> <DMCTL_COMMAND>` - Runs `dmctl` with given command in non-interactive mode.
* `run_sql <SQL> <PORT>` — Executes an SQL query in database based on port provided
* `run_sql_file <path_to_SQL_file> <HOST> <PORT>` — Executes all SQLs in given file to the database on port provided
* `run_sql_file_online_ddl <path_to_SQL_file> <HOST> <PORT> <DB> <ONLINE DDL TOOL>` — Executes all SQLs in given file, will auto switch DDL to online DDL command.
Expand Down
7 changes: 6 additions & 1 deletion tests/_utils/check_sync_diff
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
# parameter 1: work directory
# parameter 2: config file for sync_diff_inspector
# parameter 3: max check times

workdir=$1
conf=$2
check_time=10
if [ $# -ge 3 ]; then
check_time=$3
else
check_time=10
fi

PWD=$(pwd)
binary=$PWD/bin/sync_diff_inspector
Expand Down
31 changes: 31 additions & 0 deletions tests/_utils/run_dm_ctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# tools to run dmctl from command line
# parameter 1: work directory
# parameter 2: master-addr port
# parameter 3: command
# parameter 4...: check output content and count

workdir=$1
master_addr=$2
cmd=$3

shift 3

PWD=$(pwd)
binary=$PWD/bin/dmctl.test
ts=$(date +"%s")
dmctl_log=$workdir/dmctl.$ts.log
echo "dmctl test cmd: \"$cmd\""
echo "$cmd" | $binary -test.coverprofile="$TEST_DIR/cov.$TEST_NAME.dmctl.$ts.out" DEVEL -master-addr=$master_addr > $dmctl_log 2>&1

for ((i=1; i<$#; i+=2)); do
j=$((i+1))
value=${!i}
expected=${!j}
got=$(sed "s/$value/$value\n/g" $dmctl_log | grep -c "$value")
if [ "$got" != "$expected" ]; then
echo "command: $cmd $value count: $got != expected: $expected"
cat $dmctl_log
exit 1
fi
done
37 changes: 37 additions & 0 deletions tests/_utils/test_prepare
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,40 @@ fi
function join_string() {
local IFS="$1"; shift; echo "$*";
}

# shortcut for start task on one DM-worker
function dmctl_start_task_standalone() {
if [ $# -ge 1 ]; then
task_conf=$1
else
task_conf="$cur/conf/dm-task.yaml"
fi
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"start-task $task_conf" \
"\"result\": true" 2 \
"\"worker\": \"127.0.0.1:$WORKER1_PORT\"" 1
}

# shortcut for start task on two DM-workers
function dmctl_start_task() {
if [ $# -ge 1 ]; then
task_conf=$1
else
task_conf="$cur/conf/dm-task.yaml"
fi
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"start-task $task_conf" \
"\"result\": true" 3 \
"\"worker\": \"127.0.0.1:$WORKER1_PORT\"" 1 \
"\"worker\": \"127.0.0.1:$WORKER2_PORT\"" 1
}

# shortcut for stop task on two DM-workers
function dmctl_stop_task() {
task_name=$1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"stop-task $task_name" \
"\"result\": true" 3 \
"\"worker\": \"127.0.0.1:$WORKER1_PORT\"" 1 \
"\"worker\": \"127.0.0.1:$WORKER2_PORT\"" 1
}
Loading