Skip to content

Commit

Permalink
Fix SHOW VSCHEMA TABLES tests using v17 vtgate that expected dual (
Browse files Browse the repository at this point in the history
…#12381) (#12466)

* Fix SHOW VSCHEMA TABLES tests using v17 vtgate



* Fix tests expectations



---------

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Co-authored-by: Florent Poinsard <35779988+frouioui@users.noreply.github.com>
  • Loading branch information
GuptaManan100 and frouioui committed Feb 27, 2023
1 parent 12cd2f3 commit 52ab294
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
35 changes: 30 additions & 5 deletions go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,54 @@ func TestInitAndUpdate(t *testing.T) {
require.NoError(t, err)
defer conn.Close()

vtgateVersion, err := cluster.GetMajorVersion("vtgate")
require.NoError(t, err)

expected := `[[VARCHAR("dual")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`
}
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"initial table list not complete")

// Init
_ = utils.Exec(t, conn, "create table test_sc (id bigint primary key)")
expected = `[[VARCHAR("dual")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")] [VARCHAR("test_sc")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")] [VARCHAR("test_sc")]]`
}
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")] [VARCHAR("test_sc")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"test_sc not in vschema tables")

// Tables Update via health check.
_ = utils.Exec(t, conn, "create table test_sc1 (id bigint primary key)")
expected = `[[VARCHAR("dual")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")] [VARCHAR("test_sc")] [VARCHAR("test_sc1")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")] [VARCHAR("test_sc")] [VARCHAR("test_sc1")]]`
}
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")] [VARCHAR("test_sc")] [VARCHAR("test_sc1")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"test_sc1 not in vschema tables")

_ = utils.Exec(t, conn, "drop table test_sc, test_sc1")
expected = `[[VARCHAR("dual")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`
}
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"test_sc and test_sc_1 should not be in vschema tables")
Expand All @@ -204,10 +223,16 @@ func TestDMLOnNewTable(t *testing.T) {
// create a new table which is not part of the VSchema
utils.Exec(t, conn, `create table new_table_tracked(id bigint, name varchar(100), primary key(id)) Engine=InnoDB`)

vtgateVersion, err := cluster.GetMajorVersion("vtgate")
require.NoError(t, err)
expected := `[[VARCHAR("dual")] [VARCHAR("new_table_tracked")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("new_table_tracked")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`
}
// wait for vttablet's schema reload interval to pass
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("new_table_tracked")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t8")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"test_sc not in vschema tables")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,33 @@ func TestNewUnshardedTable(t *testing.T) {
require.NoError(t, err)
defer conn.Close()

vtgateVersion, err := cluster.GetMajorVersion("vtgate")
require.NoError(t, err)
expected := `[[VARCHAR("dual")] [VARCHAR("main")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("main")]]`
}

// ensuring our initial table "main" is in the schema
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("main")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"initial table list not complete")

// create a new table which is not part of the VSchema
utils.Exec(t, conn, `create table new_table_tracked(id bigint, name varchar(100), primary key(id)) Engine=InnoDB`)

expected = `[[VARCHAR("dual")] [VARCHAR("main")] [VARCHAR("new_table_tracked")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("main")] [VARCHAR("new_table_tracked")]]`
}

// waiting for the vttablet's schema_reload interval to kick in
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("main")] [VARCHAR("new_table_tracked")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"new_table_tracked not in vschema tables")
Expand All @@ -126,9 +138,13 @@ func TestNewUnshardedTable(t *testing.T) {
utils.Exec(t, conn, `drop table new_table_tracked`)

// waiting for the vttablet's schema_reload interval to kick in
expected = `[[VARCHAR("dual")] [VARCHAR("main")]]`
if vtgateVersion >= 17 {
expected = `[[VARCHAR("main")]]`
}
utils.AssertMatchesWithTimeout(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("main")]]`,
expected,
100*time.Millisecond,
3*time.Second,
"new_table_tracked not in vschema tables")
Expand Down
17 changes: 13 additions & 4 deletions go/test/endtoend/vtgate/vschema/vschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ func TestVSchema(t *testing.T) {

utils.AssertMatches(t, conn, "delete from vt_user", `[]`)

vtgateVersion, err := cluster.GetMajorVersion("vtgate")
require.NoError(t, err)

// Test empty vschema
utils.AssertMatches(t, conn, "SHOW VSCHEMA TABLES", `[]`)
if vtgateVersion >= 17 {
utils.AssertMatches(t, conn, "SHOW VSCHEMA TABLES", `[]`)
} else {
utils.AssertMatches(t, conn, "SHOW VSCHEMA TABLES", `[[VARCHAR("dual")]]`)
}

// Use the DDL to create an unsharded vschema and test again

Expand All @@ -128,9 +135,11 @@ func TestVSchema(t *testing.T) {
utils.Exec(t, conn, "commit")

// Test Showing Tables
utils.AssertMatches(t, conn,
"SHOW VSCHEMA TABLES",
`[[VARCHAR("main")] [VARCHAR("vt_user")]]`)
if vtgateVersion >= 17 {
utils.AssertMatches(t, conn, "SHOW VSCHEMA TABLES", `[[VARCHAR("main")] [VARCHAR("vt_user")]]`)
} else {
utils.AssertMatches(t, conn, "SHOW VSCHEMA TABLES", `[[VARCHAR("dual")] [VARCHAR("main")] [VARCHAR("vt_user")]]`)
}

// Test Showing Vindexes
utils.AssertMatches(t, conn, "SHOW VSCHEMA VINDEXES", `[]`)
Expand Down

0 comments on commit 52ab294

Please sign in to comment.