Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
asddongmen committed Jan 17, 2023
1 parent e817b1d commit c9aa51c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cdc/sink/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ func (s *mysqlSink) execDDLWithMaxRetries(ctx context.Context, ddl *model.DDLEve
log.Info("execute DDL failed, but error can be ignored", zap.String("query", ddl.Query), zap.Error(err))
return nil
}
if err != nil {
if err != nil && errorutil.IsRetryableDDLError(err) {
log.Warn("execute DDL with error, retry later", zap.String("query", ddl.Query), zap.Error(err))
}
return err
}, retry.WithBackoffBaseDelay(backoffBaseDelayInMs),
retry.WithBackoffMaxDelay(backoffMaxDelayInMs),
retry.WithMaxTries(defaultDDLMaxRetry),
retry.WithIsRetryableErr(cerror.IsRetryableError))
retry.WithIsRetryableErr(errorutil.IsRetryableDDLError))
}

func (s *mysqlSink) execDDL(pctx context.Context, ddl *model.DDLEvent) error {
Expand Down
18 changes: 10 additions & 8 deletions cdc/sink/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1642,19 +1642,21 @@ func TestNewMySQLSinkExecDDL(t *testing.T) {
mock.ExpectCommit()
mock.ExpectBegin()
mock.ExpectExec("USE `test`;").WillReturnResult(sqlmock.NewResult(1, 1))

mock.ExpectExec("ALTER TABLE test.t1 ADD COLUMN a int").
WillReturnError(&dmysql.MySQLError{
Number: uint16(infoschema.ErrColumnExists.Code()),
})
mock.ExpectExec("ALTER TABLE test.t1 ADD COLUMN a int").
WillReturnError(&dmysql.MySQLError{
Number: uint16(infoschema.ErrColumnExists.Code()),
})
mock.ExpectExec("ALTER TABLE test.t1 ADD PARTITION (PARTITION `p20230120` VALUES LESS THAN '2023-01-21'").
mock.ExpectRollback()

mock.ExpectBegin()
mock.ExpectExec("USE `test`;").WillReturnResult(sqlmock.NewResult(1, 1))
mock.ExpectExec("ALTER TABLE test.t1 ADD PARTITION (PARTITION `p20230120` VALUES LESS THAN '2023-01-21')").
WillReturnError(&dmysql.MySQLError{
Number: mysql.ErrPartitionMgmtOnNonpartitioned,
})
mock.ExpectRollback()

mock.ExpectClose()
return db, nil
}
Expand Down Expand Up @@ -1705,10 +1707,10 @@ func TestNewMySQLSinkExecDDL(t *testing.T) {
CommitTs: 1030,
TableInfo: &model.SimpleTableInfo{
Schema: "test",
Table: "t2",
Table: "t1",
},
Type: timodel.ActionAddTablePartition,
Query: "ALTER TABLE test.t1 ADD PARTITION (PARTITION `p20230120` VALUES LESS THAN '2023-01-21'",
Query: "ALTER TABLE test.t1 ADD PARTITION (PARTITION `p20230120` VALUES LESS THAN '2023-01-21')",
}
err = sink.EmitDDLEvent(ctx, ddl1)
require.Nil(t, err)
Expand All @@ -1719,7 +1721,7 @@ func TestNewMySQLSinkExecDDL(t *testing.T) {
require.Nil(t, err)

err = sink.EmitDDLEvent(ctx, ddl3)
require.Nil(t, cerror.IsChangefeedUnRetryableError(err))
require.True(t, cerror.IsChangefeedUnRetryableError(err))

err = sink.Close(ctx)
require.Nil(t, err)
Expand Down

0 comments on commit c9aa51c

Please sign in to comment.