diff --git a/pkg/conn/basedb.go b/pkg/conn/basedb.go index 1a99654fe8..b7c630115c 100644 --- a/pkg/conn/basedb.go +++ b/pkg/conn/basedb.go @@ -69,6 +69,10 @@ func (d *defaultDBProvider) 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 diff --git a/tests/dmctl_basic/check_list/check_task.sh b/tests/dmctl_basic/check_list/check_task.sh index 2ddfae0640..d1f190ddeb 100644 --- a/tests/dmctl_basic/check_list/check_task.sh +++ b/tests/dmctl_basic/check_list/check_task.sh @@ -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 +} diff --git a/tests/dmctl_basic/run.sh b/tests/dmctl_basic/run.sh index bd7831b1c6..2e2f24a347 100755 --- a/tests/dmctl_basic/run.sh +++ b/tests/dmctl_basic/run.sh @@ -114,6 +114,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 + dmctl_start_task check_sync_diff $WORK_DIR $cur/conf/diff_config.toml update_task_not_paused $TASK_CONF