Skip to content

Commit

Permalink
E2E Fuzzing testing for foreign keys (#13980)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 authored Sep 28, 2023
1 parent c311c66 commit 94281fd
Show file tree
Hide file tree
Showing 12 changed files with 1,598 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
uses: actions/setup-go@v4
with:
go-version: 1.21.0
go-version: 1.21.1

- name: Set up python
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
Expand Down
8 changes: 6 additions & 2 deletions go/test/endtoend/utils/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,17 @@ func compareVitessAndMySQLResults(t *testing.T, query string, vtConn *mysql.Conn
for _, row := range vtQr.Rows {
errStr += fmt.Sprintf("%s\n", row)
}
errStr += fmt.Sprintf("Vitess RowsAffected: %v\n", vtQr.RowsAffected)
errStr += "MySQL Results:\n"
for _, row := range mysqlQr.Rows {
errStr += fmt.Sprintf("%s\n", row)
}
errStr += fmt.Sprintf("MySQL RowsAffected: %v\n", mysqlQr.RowsAffected)
if vtConn != nil {
qr := Exec(t, vtConn, fmt.Sprintf("vexplain plan %s", query))
errStr += fmt.Sprintf("query plan: \n%s\n", qr.Rows[0][0].ToString())
qr, _ := ExecAllowError(t, vtConn, fmt.Sprintf("vexplain plan %s", query))
if qr != nil && len(qr.Rows) > 0 {
errStr += fmt.Sprintf("query plan: \n%s\n", qr.Rows[0][0].ToString())
}
}
t.Error(errStr)
return errors.New(errStr)
Expand Down
59 changes: 59 additions & 0 deletions go/test/endtoend/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.
package utils

import (
"context"
"fmt"
"os"
"path"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -340,3 +343,59 @@ func TimeoutAction(t *testing.T, timeout time.Duration, errMsg string, action fu
}
}
}

// 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
}

// RunSQL is used to run a SQL statement on the given tablet
func RunSQL(t *testing.T, sql string, tablet *cluster.Vttablet, db string) (*sqltypes.Result, error) {
// Get Connection
tabletParams := getMysqlConnParam(tablet, db)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
conn, err := mysql.Connect(ctx, &tabletParams)
require.Nil(t, err)
defer conn.Close()

// RunSQL
return execute(t, conn, sql)
}

// GetMySQLConn gets a MySQL connection for the given tablet
func GetMySQLConn(tablet *cluster.Vttablet, db string) (*mysql.Conn, error) {
tabletParams := getMysqlConnParam(tablet, db)
return mysql.Connect(context.Background(), &tabletParams)
}

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

func getMysqlConnParam(tablet *cluster.Vttablet, db string) mysql.ConnParams {
connParams := mysql.ConnParams{
Uname: "vt_dba",
UnixSocket: path.Join(os.Getenv("VTDATAROOT"), fmt.Sprintf("/vt_%010d/mysql.sock", tablet.TabletUID)),
}
if db != "" {
connParams.DbName = db
}
return connParams
}
Loading

0 comments on commit 94281fd

Please sign in to comment.