Skip to content

Commit

Permalink
test: add failing test for globally routed table with schema tracking
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Aug 1, 2024
1 parent 2e79d16 commit 6e54e70
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions go/test/endtoend/vtgate/gen4/gen4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,31 @@ func TestDualJoinQueries(t *testing.T) {
mcmp.Exec("select t.title, t2.id from t2 left join (select 'ABC' as title) as t on t.title = t2.tcol1")

}

// TestSchemaTrackingGlobalTables tests that schema tracking works as intended with global table routing.
// This test creates a new table in a schema and verifies we can query it without needing to add it to the vschema as long
// as the name of the table is unique.
func TestSchemaTrackingGlobalTables(t *testing.T) {
// Create a new vtgate connection.
vtConn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer vtConn.Close()

// Create a new table in the unsharded keyspace such that it has a unique name that allows for global routing.
utils.Exec(t, vtConn, `use `+unshardedKs)
utils.Exec(t, vtConn, `create table uniqueTableName(id int, primary key(id))`)
defer utils.Exec(t, vtConn, `drop table uniqueTableName`)

// Wait for schema tracking to see this column.
err = utils.WaitForAuthoritative(t, unshardedKs, "uniqueTableName", clusterInstance.VtgateProcess.ReadVSchema)
require.NoError(t, err)

// Create a new vtgate connection.
vtConnTwo, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer vtConnTwo.Close()
// Insert rows into the table and select them to verify we can use them.
utils.Exec(t, vtConnTwo, `insert into uniqueTableName(id) values (1),(2)`)
require.NoError(t, err)
utils.AssertMatches(t, vtConnTwo, `select * from uniqueTableName order by id`, `[[INT32(1)] [INT32(2)]]`)
}

0 comments on commit 6e54e70

Please sign in to comment.