diff --git a/src/mysql/api_test.go b/src/mysql/api_test.go index 96cfb35..2a9d07e 100644 --- a/src/mysql/api_test.go +++ b/src/mysql/api_test.go @@ -28,7 +28,7 @@ func TestSetReadOnly(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -56,7 +56,7 @@ func TestStartSlaveIOThread(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "START SLAVE IO_THREAD" @@ -73,7 +73,7 @@ func TestStopSlaveIOThread(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "STOP SLAVE IO_THREAD" @@ -90,7 +90,7 @@ func TestStartSlave(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "START SLAVE" @@ -107,7 +107,7 @@ func TestStopSlave(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "STOP SLAVE" @@ -124,7 +124,7 @@ func TestChangeMasterTo(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{"STOP SLAVE", @@ -148,7 +148,7 @@ func TestChangeToMaster(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{"STOP SLAVE", @@ -169,7 +169,7 @@ func TestWaitUntilAfterGTID(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "SELECT WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS('1')" @@ -186,7 +186,7 @@ func TestGetLocalGTID(t *testing.T) { //log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "SELECT @@SERVER_UUID" @@ -208,7 +208,7 @@ func TestCheckGTID(t *testing.T) { //log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db // local is a normal follower, leader Executed_GTID_Set is "" @@ -368,7 +368,7 @@ func TestGTIDGreaterThan(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db // 1. show slave status OK @@ -513,7 +513,7 @@ func TestGetGTID(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db // 1. show slave status OK @@ -634,7 +634,7 @@ func TestPromotableYes(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db // 2. mock Slave_SQL_Running OK @@ -684,7 +684,7 @@ func TestPromotableNot(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db // 1. mock MysqlDead @@ -791,7 +791,7 @@ func TestWaitMysqlWorks(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db mysql.PingStart() defer mysql.PingStop() @@ -799,7 +799,7 @@ func TestWaitMysqlWorks(t *testing.T) { // works { conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "SHOW SLAVE STATUS" @@ -816,14 +816,14 @@ func TestWaitMysqlWorks(t *testing.T) { "Yes", "Yes") mock.ExpectQuery(query).WillReturnRows(mockRows) - err = mysql.WaitMysqlWorks(10000) + err = mysql.WaitMysqlWorks(QueryTimeout) assert.Nil(t, err) } // timeouts { conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db mysql.PingStart() defer mysql.PingStop() @@ -846,7 +846,7 @@ func TestGlobalSysVar(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -877,7 +877,7 @@ func TestSemiSyncMaster(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -895,7 +895,7 @@ func TestSemiSyncMaster(t *testing.T) { assert.Nil(t, err) mock.ExpectExec(queryList[2]).WillReturnResult(sqlmock.NewResult(1, 1)) - err = mysql.SetSemiSyncMasterTimeout(10000) + err = mysql.SetSemiSyncMasterTimeout(SemiSyncTimeout) assert.Nil(t, err) } @@ -907,7 +907,7 @@ func TestPurgeBinlogsTo(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db // 1. show slave status OK @@ -926,7 +926,7 @@ func TestSetMasterSysVars(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.ERROR)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db err = mysql.SetMasterGlobalSysVar() assert.Nil(t, err) @@ -960,7 +960,7 @@ func TestSetSlaveSysVars(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.ERROR)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db err = mysql.SetSlaveGlobalSysVar() diff --git a/src/mysql/mock.go b/src/mysql/mock.go index 8a230dc..576790b 100644 --- a/src/mysql/mock.go +++ b/src/mysql/mock.go @@ -21,6 +21,11 @@ import ( "github.com/stretchr/testify/assert" ) +const ( + QueryTimeout int = 10000 + SemiSyncTimeout uint64 = 10000 +) + // MockGTID tuple. type MockGTID struct { SetQueryTimeoutFn func(int) @@ -1082,7 +1087,7 @@ func NewMockGTIDX5ChangeToMasterError() *MockGTID { func MockMysql(log *xlog.Log, port int, h MysqlHandler) (string, *Mysql, func()) { id := fmt.Sprintf("127.0.0.1:%d", port) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) // setup rpc rpc, err := xrpc.NewService(xrpc.Log(log), @@ -1108,7 +1113,7 @@ func MockMysql(log *xlog.Log, port int, h MysqlHandler) (string, *Mysql, func()) func MockMysqlReplUser(log *xlog.Log, port int, h MysqlHandler) (string, *Mysql, func()) { id := fmt.Sprintf("127.0.0.1:%d", port) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) // setup rpc rpc, err := xrpc.NewService(xrpc.Log(log), diff --git a/src/mysql/mysql56_test.go b/src/mysql/mysql56_test.go index eae7e6d..964c697 100644 --- a/src/mysql/mysql56_test.go +++ b/src/mysql/mysql56_test.go @@ -24,9 +24,9 @@ func TestMysql56Handler(t *testing.T) { conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) want := new(Mysql56) - want.SetQueryTimeout(10000) + want.SetQueryTimeout(QueryTimeout) got := mysql.mysqlHandler assert.Equal(t, want, got) } @@ -40,7 +40,7 @@ func TestMysql56SetSemiWaitSlaveCount(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql56 := NewMysql(conf, 10000, log) + mysql56 := NewMysql(conf, QueryTimeout, log) mysql56.db = db queryList := []string{ @@ -61,7 +61,7 @@ func TestMysql56ChangeUserPassword(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql56 := NewMysql(conf, 10000, log) + mysql56 := NewMysql(conf, QueryTimeout, log) mysql56.db = db queryList := []string{ @@ -82,7 +82,7 @@ func TestMysql56CreateUser(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql56 := NewMysql(conf, 10000, log) + mysql56 := NewMysql(conf, QueryTimeout, log) mysql56.db = db // ssl is NO @@ -119,7 +119,7 @@ func TestMysql56CreateUserWithPrivileges(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql56 := NewMysql(conf, 10000, log) + mysql56 := NewMysql(conf, QueryTimeout, log) mysql56.db = db queryList := []string{ @@ -162,7 +162,7 @@ func TestMysql56CreateUserWithPrivilegesError(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql56 := NewMysql(conf, 10000, log) + mysql56 := NewMysql(conf, QueryTimeout, log) mysql56.db = db queryList := []string{ @@ -205,7 +205,7 @@ func TestMysql56GrantAllPrivileges(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql56 := NewMysql(conf, 10000, log) + mysql56 := NewMysql(conf, QueryTimeout, log) mysql56.db = db queryList := []string{ @@ -249,7 +249,7 @@ func TestMysql56GrantAllPrivilegesError(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() conf.Version = "mysql56" - mysql56 := NewMysql(conf, 10000, log) + mysql56 := NewMysql(conf, QueryTimeout, log) mysql56.db = db queryList := []string{ diff --git a/src/mysql/mysql57_test.go b/src/mysql/mysql57_test.go index 3a88f6d..de5e2a7 100644 --- a/src/mysql/mysql57_test.go +++ b/src/mysql/mysql57_test.go @@ -22,9 +22,9 @@ func TestMysql57Handler(t *testing.T) { log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) want := new(Mysql57) - want.SetQueryTimeout(10000) + want.SetQueryTimeout(QueryTimeout) got := mysql.mysqlHandler assert.Equal(t, want, got) } diff --git a/src/mysql/mysql_test.go b/src/mysql/mysql_test.go index 8cd4402..8d3c235 100644 --- a/src/mysql/mysql_test.go +++ b/src/mysql/mysql_test.go @@ -74,7 +74,7 @@ func TestMysqlGTIDGreatThan(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.PANIC)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) // Set mock functions mysql.SetMysqlHandler(new(MockGTIDB)) diff --git a/src/mysql/mysqlbase_test.go b/src/mysql/mysqlbase_test.go index 98d118e..f470129 100644 --- a/src/mysql/mysqlbase_test.go +++ b/src/mysql/mysqlbase_test.go @@ -26,7 +26,7 @@ var mysqlbase = new(MysqlBase) func TestMysqlBasePing(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() query := "SHOW SLAVE STATUS" @@ -51,7 +51,7 @@ func TestMysqlBasePing(t *testing.T) { func TestMysqlBaseGetSlaveGTIDGotZeroRow(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() query := "SHOW SLAVE STATUS" @@ -77,7 +77,7 @@ func TestMysqlBaseGetSlaveGTIDGotZeroRow(t *testing.T) { func TestMysqlBaseGetSlaveGTID(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() query := "SHOW SLAVE STATUS" @@ -127,7 +127,7 @@ func TestMysqlBaseGetMasterGTID(t *testing.T) { { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() query := "SHOW MASTER STATUS" @@ -166,7 +166,7 @@ func TestMysqlBaseGetMasterGTID(t *testing.T) { func TestGetUUID(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() query := "SELECT @@SERVER_UUID" @@ -183,7 +183,7 @@ func TestGetUUID(t *testing.T) { func TestMysqlBaseChangeMasterToCommand(t *testing.T) { db, _, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() want := []string{ @@ -206,7 +206,7 @@ func TestMysqlBaseChangeMasterToCommand(t *testing.T) { func TestMysqlBaseChangeMasterTo(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{"STOP SLAVE", @@ -229,7 +229,7 @@ func TestMysqlBaseChangeMasterTo(t *testing.T) { func TestMysqlBaseChangeToMaster(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{"STOP SLAVE", @@ -245,7 +245,7 @@ func TestMysqlBaseChangeToMaster(t *testing.T) { func TestMysqlBaseSlaveIOThread(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{ @@ -265,7 +265,7 @@ func TestMysqlBaseSlaveIOThread(t *testing.T) { func TestMysqlBaseReadOnly(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{ @@ -289,7 +289,7 @@ func TestMysqlBaseReadOnly(t *testing.T) { func TestMysqlBaseSetGlobalVar(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{ @@ -315,7 +315,7 @@ func TestMysqlBaseSetGlobalVar(t *testing.T) { func TestMysqlBaseResetMaster(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{ @@ -330,7 +330,7 @@ func TestMysqlBaseResetMaster(t *testing.T) { func TestMysqlBasePurgeBinlogsTo(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{ @@ -345,7 +345,7 @@ func TestMysqlBasePurgeBinlogsTo(t *testing.T) { func TestMysqlBaseSemiMaster(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{ @@ -365,7 +365,7 @@ func TestMysqlBaseSemiMaster(t *testing.T) { func TestMysqlBaseSemiMasterTimeout(t *testing.T) { db, mock, err := sqlmock.New() assert.Nil(t, err) - mysqlbase.SetQueryTimeout(10000) + mysqlbase.SetQueryTimeout(QueryTimeout) defer db.Close() queryList := []string{ @@ -373,7 +373,7 @@ func TestMysqlBaseSemiMasterTimeout(t *testing.T) { } mock.ExpectExec(queryList[0]).WillReturnResult(sqlmock.NewResult(1, 1)) - err = mysqlbase.SetSemiSyncMasterTimeout(db, 10000) + err = mysqlbase.SetSemiSyncMasterTimeout(db, SemiSyncTimeout) assert.Nil(t, err) } @@ -385,7 +385,7 @@ func TestCheckUserExists(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "SELECT User FROM mysql.user WHERE User = 'xx' and Host = '192.168.0.%'" @@ -409,7 +409,7 @@ func TestCreateUser(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db querys := []string{ @@ -468,7 +468,7 @@ func TestCreateUserError(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db querys := []string{ @@ -513,7 +513,7 @@ func TestCreateUserWithPrivileges(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -543,7 +543,7 @@ func TestGetUser(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "SELECT User, Host, Super_priv FROM mysql.user" @@ -574,7 +574,7 @@ func TestDropUser(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "DROP USER `xx`@`127.0.0.1`" @@ -591,7 +591,7 @@ func TestCreateReplUserWithoutBinlog(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -617,7 +617,7 @@ func TestCreateReplUserWithoutBinlogErr(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -645,7 +645,7 @@ func TestChangeUserPasswd(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "ALTER USER `xx`@`localhost` IDENTIFIED BY 'xxx'" @@ -662,7 +662,7 @@ func TestGrantAllPrivileges(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -692,7 +692,7 @@ func TestGrantAllPrivilegesError(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db queryList := []string{ @@ -725,7 +725,7 @@ func TestGrantNormalPrivileges(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "GRANT ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,DROP,EXECUTE,EVENT,INDEX,INSERT,LOCK TABLES,PROCESS,RELOAD,SELECT,SHOW DATABASES,SHOW VIEW,UPDATE,TRIGGER,REFERENCES,REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO `xx`@`127.0.0.1`" @@ -742,7 +742,7 @@ func TestGrantReplicationPrivileges(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db query := "GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO `xx`" @@ -759,7 +759,7 @@ func TestGrantUserPrivileges(t *testing.T) { // log log := xlog.NewStdLog(xlog.Level(xlog.DEBUG)) conf := config.DefaultMysqlConfig() - mysql := NewMysql(conf, 10000, log) + mysql := NewMysql(conf, QueryTimeout, log) mysql.db = db user := "xx" diff --git a/src/raft/mock.go b/src/raft/mock.go index dc43287..5f2802f 100644 --- a/src/raft/mock.go +++ b/src/raft/mock.go @@ -28,6 +28,11 @@ var ( longHeartbeatTimeoutForTest = 500 ) +const ( + QueryTimeout int = 10000 + SemiSyncTimeout uint64 = 10000 +) + func setupRPC(rpc *xrpc.Service, raft *Raft) { if err := rpc.RegisterService(raft.GetHARPC()); err != nil { raft.PANIC("server.rpc.RegisterService.HARPC.error[%+v]", err) @@ -84,15 +89,15 @@ func mockRafts(log *xlog.Log, conf *config.RaftConfig, port int, count int, idle } // setup mysql - mysql57 := mysql.NewMysql(config.DefaultMysqlConfig(), 10000, log) + mysql57 := mysql.NewMysql(config.DefaultMysqlConfig(), QueryTimeout, log) mysql57.SetMysqlHandler(mysql.NewMockGTIDA()) mysql57.PingStart() for i, id := range ids { if idleStart != -1 && i >= idleStart { - raft = NewRaft(id, conf, 10000, log, mysql57, IDLE) + raft = NewRaft(id, conf, SemiSyncTimeout, log, mysql57, IDLE) } else { - raft = NewRaft(id, conf, 10000, log, mysql57, FOLLOWER) + raft = NewRaft(id, conf, SemiSyncTimeout, log, mysql57, FOLLOWER) } } diff --git a/src/server/server.go b/src/server/server.go index bc84c63..5db4232 100644 --- a/src/server/server.go +++ b/src/server/server.go @@ -22,6 +22,9 @@ import ( "xbase/xrpc" ) +// execute timeout: 60s +const TIMEOUT int = 60 * 1000 + type RPCS struct { NodeRPC *NodeRPC ServerRPC *ServerRPC @@ -83,7 +86,7 @@ func (s *Server) setupMysqld() { func (s *Server) setupMysql() { log := s.log log.Info("server.mysql.wait.for.work[maxwait:60s]") - if err := s.mysql.WaitMysqlWorks(60 * 1000); err != nil { + if err := s.mysql.WaitMysqlWorks(TIMEOUT); err != nil { log.Error("server.mysql.WaitMysqlWorks.error[%v]", err) return }