From 2d1f5a312854ce6560ab28056b71f96b019b874d Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Mon, 8 Apr 2024 13:14:42 +0530 Subject: [PATCH] refactor: store the entire mycnf Signed-off-by: Manan Gupta --- go/test/endtoend/utils/mysql.go | 19 ++++++++----------- go/test/endtoend/utils/mysql_test.go | 5 +++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/go/test/endtoend/utils/mysql.go b/go/test/endtoend/utils/mysql.go index dc8ac5c4fc0..a522af2472e 100644 --- a/go/test/endtoend/utils/mysql.go +++ b/go/test/endtoend/utils/mysql.go @@ -38,8 +38,6 @@ import ( const mysqlShutdownTimeout = 1 * time.Minute -var serverID uint32 - // NewMySQL creates a new MySQL server using the local mysqld binary. The name of the database // will be set to `dbName`. SQL queries that need to be executed on the new MySQL instance // can be passed through the `schemaSQL` argument. @@ -56,7 +54,7 @@ func NewMySQL(cluster *cluster.LocalProcessCluster, dbName string, schemaSQL ... } sqls = append(sqls, split...) } - mysqlParam, _, closer, error := NewMySQLWithMysqld(cluster.GetAndReservePort(), cluster.Hostname, dbName, sqls...) + mysqlParam, _, _, closer, error := NewMySQLWithMysqld(cluster.GetAndReservePort(), cluster.Hostname, dbName, sqls...) return mysqlParam, closer, error } @@ -67,7 +65,6 @@ func CreateMysqldAndMycnf(tabletUID uint32, mysqlSocket string, mysqlPort int) ( if err := mycnf.RandomizeMysqlServerID(); err != nil { return nil, nil, fmt.Errorf("couldn't generate random MySQL server_id: %v", err) } - serverID = mycnf.ServerID if mysqlSocket != "" { mycnf.SocketFile = mysqlSocket } @@ -78,24 +75,24 @@ func CreateMysqldAndMycnf(tabletUID uint32, mysqlSocket string, mysqlPort int) ( return mysqlctl.NewMysqld(&cfg), mycnf, nil } -func NewMySQLWithMysqld(port int, hostname, dbName string, schemaSQL ...string) (mysql.ConnParams, *mysqlctl.Mysqld, func(), error) { +func NewMySQLWithMysqld(port int, hostname, dbName string, schemaSQL ...string) (mysql.ConnParams, *mysqlctl.Mysqld, *mysqlctl.Mycnf, func(), error) { mysqlDir, err := createMySQLDir() if err != nil { - return mysql.ConnParams{}, nil, nil, err + return mysql.ConnParams{}, nil, nil, nil, err } initMySQLFile, err := createInitSQLFile(mysqlDir, dbName) if err != nil { - return mysql.ConnParams{}, nil, nil, err + return mysql.ConnParams{}, nil, nil, nil, err } mysqlPort := port mysqld, mycnf, err := CreateMysqldAndMycnf(0, "", mysqlPort) if err != nil { - return mysql.ConnParams{}, nil, nil, err + return mysql.ConnParams{}, nil, nil, nil, err } err = initMysqld(mysqld, mycnf, initMySQLFile) if err != nil { - return mysql.ConnParams{}, nil, nil, err + return mysql.ConnParams{}, nil, nil, nil, err } params := mysql.ConnParams{ @@ -107,10 +104,10 @@ func NewMySQLWithMysqld(port int, hostname, dbName string, schemaSQL ...string) for _, sql := range schemaSQL { err = prepareMySQLWithSchema(params, sql) if err != nil { - return mysql.ConnParams{}, nil, nil, err + return mysql.ConnParams{}, nil, nil, nil, err } } - return params, mysqld, func() { + return params, mysqld, mycnf, func() { ctx := context.Background() _ = mysqld.Teardown(ctx, mycnf, true, mysqlShutdownTimeout) }, nil diff --git a/go/test/endtoend/utils/mysql_test.go b/go/test/endtoend/utils/mysql_test.go index 6ff962baa51..ae550e34864 100644 --- a/go/test/endtoend/utils/mysql_test.go +++ b/go/test/endtoend/utils/mysql_test.go @@ -35,6 +35,7 @@ var ( clusterInstance *cluster.LocalProcessCluster mysqlParams mysql.ConnParams mysqld *mysqlctl.Mysqld + mycnf *mysqlctl.Mycnf keyspaceName = "ks" cell = "test" schemaSQL = `create table t1( @@ -54,7 +55,7 @@ func TestMain(m *testing.M) { var closer func() var err error - mysqlParams, mysqld, closer, err = NewMySQLWithMysqld(clusterInstance.GetAndReservePort(), clusterInstance.Hostname, keyspaceName, schemaSQL) + mysqlParams, mysqld, mycnf, closer, err = NewMySQLWithMysqld(clusterInstance.GetAndReservePort(), clusterInstance.Hostname, keyspaceName, schemaSQL) if err != nil { fmt.Println(err) return 1 @@ -142,7 +143,7 @@ func TestGetServerID(t *testing.T) { sid, err := mysqld.GetServerID(context.Background()) assert.NoError(t, err) - assert.Equal(t, serverID, sid) + assert.Equal(t, mycnf.ServerID, sid) suuid, err := mysqld.GetServerUUID(context.Background()) assert.NoError(t, err)