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

check_task: ping db when apply dbconfig #769

Merged
merged 5 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions dm/master/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -1136,6 +1137,7 @@ func (t *testMaster) TestOperateSource(c *check.C) {
defer s1.Close()
mysqlCfg := config.NewSourceConfig()
mysqlCfg.LoadFromFile("./source.toml")
mysqlCfg.From.Password = os.Getenv("MYSQL_PSWD")
task, err := mysqlCfg.Toml()
c.Assert(err, check.IsNil)
sourceID := mysqlCfg.SourceID
Expand Down
4 changes: 4 additions & 0 deletions pkg/conn/basedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (d *DefaultDBProviderImpl) Apply(config config.DBConfig) (*BaseDB, error) {
return nil, terror.DBErrorAdapt(err, terror.ErrDBDriverError)
}

if err = db.Ping(); err != nil {
return nil, terror.DBErrorAdapt(err, terror.ErrDBDriverError)
}

db.SetMaxIdleConns(maxIdleConns)

return NewBaseDB(db), nil
Expand Down
7 changes: 7 additions & 0 deletions tests/dmctl_basic/check_list/check_task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ function check_task_not_pass() {
"check-task $task_conf" \
"\"result\": false" 1
}

function check_task_error_database_config() {
task_conf=$1
run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"check-task $task_conf" \
"database driver error" 1
}
4 changes: 4 additions & 0 deletions tests/dmctl_basic/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ function run() {
check_task_pass $TASK_CONF
check_task_not_pass $cur/conf/dm-task2.yaml

cp $cur/conf/dm-task.yaml $WORK_DIR/dm-task-error-database-config.yaml
sed -i "s/password: \"\"/password: \"wrond password\"/g" $WORK_DIR/dm-task-error-database-config.yaml
check_task_error_database_config $WORK_DIR/dm-task-error-database-config.yaml

echo "dmctl_start_task"
dmctl_start_task
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml
Expand Down