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

E2E Fuzzing testing for foreign keys #13980

Merged
merged 17 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
10077a5
feat: add preliminary fuzzer test that only runs inserts
GuptaManan100 Sep 14, 2023
61b34d3
feat: remove collision map and add code to store the debug informatio…
GuptaManan100 Sep 14, 2023
748f683
feat: augment tests to verify that a replica without any foreign key …
GuptaManan100 Sep 14, 2023
3257598
feat: add tests for multicol foreign keys as well
GuptaManan100 Sep 15, 2023
055765b
feat: wait for replica to be caught up before verifying that data mat…
GuptaManan100 Sep 15, 2023
ed7129f
Merge remote-tracking branch 'upstream/main' into fk-e2e-fuzzing
GuptaManan100 Sep 15, 2023
1630cb0
Merge remote-tracking branch 'upstream/main' into fk-e2e-fuzzing
GuptaManan100 Sep 18, 2023
f518818
feat: augment the test with prepared statements too
GuptaManan100 Sep 18, 2023
313f8cf
Merge remote-tracking branch 'upstream/main' into fk-e2e-fuzzing
GuptaManan100 Sep 19, 2023
55be828
Merge remote-tracking branch 'upstream/main' into fk-e2e-fuzzing
GuptaManan100 Sep 21, 2023
d767319
feat: fix build issue in test
GuptaManan100 Sep 22, 2023
d270f00
Merge remote-tracking branch 'upstream/main' into fk-e2e-fuzzing
GuptaManan100 Sep 22, 2023
429ae96
test: queryFormat as a type instead of a preparedstaement boolean
GuptaManan100 Sep 22, 2023
27a2c06
feat: add prepared statements using COM_PREPARED as packets as a new …
GuptaManan100 Sep 23, 2023
b2ac29c
Merge remote-tracking branch 'upstream/main' into fk-e2e-fuzzing
GuptaManan100 Sep 25, 2023
aa150c3
feat: move foreign key tests into a single package
GuptaManan100 Sep 25, 2023
89847e0
Merge remote-tracking branch 'upstream/main' into fk-e2e-fuzzing
GuptaManan100 Sep 26, 2023
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
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
Loading