Skip to content

Commit

Permalink
add RunSQLs
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Jan 18, 2024
1 parent 022a8fd commit c07ed7b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions go/test/endtoend/vtorc/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,26 @@ func RunSQL(t *testing.T, sql string, tablet *cluster.Vttablet, db string) (*sql
return execute(t, conn, sql)
}

// RunSQLs is used to run a list of SQL statements on the given tablet
func RunSQLs(t *testing.T, sqls []string, tablet *cluster.Vttablet, db string) error {
// Get Connection
tabletParams := getMysqlConnParam(tablet, db)
var timeoutDuration = time.Duration(5 * len(sqls))
ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration*time.Second)
defer cancel()
conn, err := mysql.Connect(ctx, &tabletParams)
require.Nil(t, err)
defer conn.Close()

// Run SQLs
for _, sql := range sqls {
if _, err := execute(t, conn, sql); err != nil {
return err
}
}
return nil
}

func execute(t *testing.T, conn *mysql.Conn, query string) (*sqltypes.Result, error) {
t.Helper()
return conn.ExecuteFetch(query, 1000, true)
Expand Down

0 comments on commit c07ed7b

Please sign in to comment.