You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1008 B
26 lines
1008 B
package mysql
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
mysqldrv "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
// 只有「对方已经建好了」这类冲突才重试;其余错误(权限、语法、连接断开)照旧直接返回。
|
|
func TestIsConcurrentDDLConflict(t *testing.T) {
|
|
cases := map[error]bool{
|
|
&mysqldrv.MySQLError{Number: 1060, Message: "Duplicate column name 'computeuser'"}: true,
|
|
&mysqldrv.MySQLError{Number: 1050, Message: "Table already exists"}: true,
|
|
&mysqldrv.MySQLError{Number: 1061, Message: "Duplicate key name"}: true,
|
|
fmt.Errorf("wrap: %w", &mysqldrv.MySQLError{Number: 1060}): true,
|
|
&mysqldrv.MySQLError{Number: 1142, Message: "ALTER command denied"}: false,
|
|
errors.New("driver: bad connection"): false,
|
|
}
|
|
for err, want := range cases {
|
|
if got := isConcurrentDDLConflict(err); got != want {
|
|
t.Errorf("%v → %v, want %v", err, got, want)
|
|
}
|
|
}
|
|
}
|
|
|