Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*.: fix magic number #121 #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
48 changes: 24 additions & 24 deletions src/mysql/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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')"
Expand All @@ -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"
Expand All @@ -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 ""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -791,15 +791,15 @@ 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()

// works
{
conf := config.DefaultMysqlConfig()
mysql := NewMysql(conf, 10000, log)
mysql := NewMysql(conf, QueryTimeout, log)
mysql.db = db

query := "SHOW SLAVE STATUS"
Expand All @@ -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()
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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)
}

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions src/mysql/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
18 changes: 9 additions & 9 deletions src/mysql/mysql56_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions src/mysql/mysql57_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion src/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading