Skip to content

Commit

Permalink
test: change to table driven test
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Jan 7, 2025
1 parent 734f341 commit a736cb8
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions go/test/endtoend/vtgate/queries/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"testing"
"time"

"vitess.io/vitess/go/vt/log"

"vitess.io/vitess/go/mysql"

_ "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -192,33 +194,38 @@ func TestSetAndGetLastInsertIDWithInsert(t *testing.T) {
mcmp, closer := start(t)
defer closer()

mcmp.Exec("insert into t1(id1, id2) values (last_insert_id(12),0)")
mcmp.Exec("select last_insert_id()")
mcmp.Exec("insert into t1(id1, id2) values (13,last_insert_id(0))")
mcmp.Exec("select last_insert_id()")

mcmp.Exec("begin")
mcmp.Exec("insert into t1(id1, id2) values (last_insert_id(14),0)")
mcmp.Exec("select last_insert_id()")
mcmp.Exec("insert into t1(id1, id2) values (15,last_insert_id(0))")
mcmp.Exec("select last_insert_id()")
mcmp.Exec("commit")
tests := []string{
"insert into t1(id1, id2) values (last_insert_id(%d),%d)",
"insert into t1(id1, id2) values (%d, last_insert_id(%d))",
}

_, err := mcmp.VtConn.ExecuteFetch("set workload = olap", 1, false)
require.NoError(t, err)
i := 0
getVal := func() int {
defer func() { i++ }()
return i
}

mcmp.Exec("insert into t1(id1, id2) values (last_insert_id(16),0)")
mcmp.Exec("select last_insert_id()")
mcmp.Exec("insert into t1(id1, id2) values (17,last_insert_id(0))")
mcmp.Exec("select last_insert_id()")
runTests := func(mcmp *utils.MySQLCompare) {
for _, test := range tests {
query := fmt.Sprintf(test, getVal(), getVal())
log.Errorf("test: %s", query)
mcmp.Exec(query)
mcmp.Exec("select last_insert_id()")
}
}

mcmp.Exec("begin")
mcmp.Exec("insert into t1(id1, id2) values (last_insert_id(18),0)")
mcmp.Exec("select last_insert_id()")
mcmp.Exec("insert into t1(id1, id2) values (19,last_insert_id(0))")
mcmp.Exec("select last_insert_id()")
mcmp.Exec("commit")
for _, workload := range []string{"olap", "oltp"} {
mcmp.Run(workload, func(mcmp *utils.MySQLCompare) {
_, err := mcmp.VtConn.ExecuteFetch("set workload = "+workload, 1, false)
require.NoError(t, err)
runTests(mcmp)

// run the queries again, but inside a transaction this time
mcmp.Exec("begin")
runTests(mcmp)
mcmp.Exec("commit")
})
}
}

// TestVindexHints tests that vindex hints work as intended.
Expand Down

0 comments on commit a736cb8

Please sign in to comment.