Skip to content

Commit

Permalink
test: added e2e and fuzz test
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Mar 20, 2024
1 parent 30bff59 commit 657f2b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
27 changes: 26 additions & 1 deletion go/test/endtoend/vtgate/foreignkey/fk_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,17 @@ func (fz *fuzzer) generateInsertDMLQuery(insertType string) string {
}
}

// generateUpdateDMLQuery generates an UPDATE query from the parameters for the fuzzer.
// generateUpdateDMLQuery generates a UPDATE query from the parameters for the fuzzer.
func (fz *fuzzer) generateUpdateDMLQuery() string {
multiTableUpdate := rand.IntN(2) + 1
if multiTableUpdate == 1 {
return fz.generateSingleUpdateDMLQuery()
}
return fz.generateMultiUpdateDMLQuery()
}

// generateSingleUpdateDMLQuery generates an UPDATE query from the parameters for the fuzzer.
func (fz *fuzzer) generateSingleUpdateDMLQuery() string {
tableId := rand.IntN(len(fkTables))
idValue := 1 + rand.IntN(fz.maxValForId)
tableName := fkTables[tableId]
Expand Down Expand Up @@ -195,6 +204,22 @@ func (fz *fuzzer) generateUpdateDMLQuery() string {
}
}

// generateMultiUpdateDMLQuery generates a UPDATE query using 2 tables from the parameters for the fuzzer.
func (fz *fuzzer) generateMultiUpdateDMLQuery() string {
tableId := rand.IntN(len(fkTables))
tableId2 := rand.IntN(len(fkTables))
idValue := 1 + rand.IntN(fz.maxValForId)
colValue := convertIntValueToString(rand.IntN(1 + fz.maxValForCol))
col2Value := convertIntValueToString(rand.IntN(1 + fz.maxValForCol))
setVarFkChecksVal := fz.getSetVarFkChecksVal()
setExprs := fmt.Sprintf("%v.col = %v", fkTables[tableId], colValue)
if rand.IntN(2)%2 == 0 {
setExprs += ", " + fmt.Sprintf("%v.col = %v", fkTables[tableId2], col2Value)
}
query := fmt.Sprintf("update %v%v join %v using (id) set %s where %v.id = %v", setVarFkChecksVal, fkTables[tableId], fkTables[tableId2], setExprs, fkTables[tableId], idValue)
return query
}

// generateDeleteDMLQuery generates a DELETE query using 1 table from the parameters for the fuzzer.
func (fz *fuzzer) generateSingleDeleteDMLQuery() string {
tableId := rand.IntN(len(fkTables))
Expand Down
30 changes: 30 additions & 0 deletions go/test/endtoend/vtgate/foreignkey/fk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,36 @@ func TestFkScenarios(t *testing.T) {
"select * from fk_multicol_t17 order by id",
"select * from fk_multicol_t19 order by id",
},
}, {
name: "Multi Table Update with non-literal update",
dataQueries: []string{
"insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)",
"insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)",
"insert into fk_multicol_t17(id, cola, colb) values (1, 7, 1)",
"insert into fk_multicol_t19(id, cola, colb) values (1, 7, 1)",
},
dmlQuery: "update fk_multicol_t15 m1 join fk_multicol_t17 on m1.id = fk_multicol_t17.id set m1.cola = m1.id + 8 where m1.id < 3",
assertionQueries: []string{
"select * from fk_multicol_t15 order by id",
"select * from fk_multicol_t16 order by id",
"select * from fk_multicol_t17 order by id",
"select * from fk_multicol_t19 order by id",
},
}, {
name: "Multi Target Update with non-literal update",
dataQueries: []string{
"insert into fk_multicol_t15(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)",
"insert into fk_multicol_t16(id, cola, colb) values (1, 7, 1), (2, 9, 1), (3, 12, 1)",
"insert into fk_multicol_t17(id, cola, colb) values (1, 7, 1), (2, 9, 1)",
"insert into fk_multicol_t19(id, cola, colb) values (1, 7, 1)",
},
dmlQuery: "update fk_multicol_t15 m1 join fk_multicol_t17 on m1.id = fk_multicol_t17.id set m1.cola = m1.id + 8, fk_multicol_t17.colb = 32 where m1.id < 3",
assertionQueries: []string{
"select * from fk_multicol_t15 order by id",
"select * from fk_multicol_t16 order by id",
"select * from fk_multicol_t17 order by id",
"select * from fk_multicol_t19 order by id",
},
},
}

Expand Down

0 comments on commit 657f2b3

Please sign in to comment.