Skip to content

Commit

Permalink
Fix some more test failures.
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schreiber <[email protected]>
  • Loading branch information
arthurschreiber committed May 5, 2024
1 parent 9a9fa81 commit ed0da79
Showing 1 changed file with 89 additions and 46 deletions.
135 changes: 89 additions & 46 deletions go/vt/vttablet/tabletserver/schema/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ func TestOpenAndReload(t *testing.T) {
db := fakesqldb.New(t)
defer db.Close()
schematest.AddDefaultQueries(db)
db.AddQueryPattern(baseShowTablesPattern,
&sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
RowsAffected: 0,
InsertID: 0,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table_01", false, ""),
mysql.BaseShowTablesRow("test_table_02", false, ""),
mysql.BaseShowTablesRow("test_table_03", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
},
SessionStateChanges: "",
StatusFlags: 0,
})

db.RejectQueryPattern(baseShowTablesPattern, "Opening schema engine should query tables without size information")

db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
RowsAffected: 0,
InsertID: 0,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table_01", false, ""),
mysql.BaseShowTablesRow("test_table_02", false, ""),
mysql.BaseShowTablesRow("test_table_03", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
},
SessionStateChanges: "",
StatusFlags: 0,
})

// advance to one second after the default 1427325875.
db.AddQuery("select unix_timestamp()", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
Expand All @@ -87,8 +89,8 @@ func TestOpenAndReload(t *testing.T) {

want := initialSchema()
mustMatch(t, want, se.GetSchema())
assert.Equal(t, int64(100), se.tableFileSizeGauge.Counts()["msg"])
assert.Equal(t, int64(150), se.tableAllocatedSizeGauge.Counts()["msg"])
assert.Equal(t, int64(0), se.tableFileSizeGauge.Counts()["msg"])
assert.Equal(t, int64(0), se.tableAllocatedSizeGauge.Counts()["msg"])

// Advance time some more.
db.AddQuery("select unix_timestamp()", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
Expand Down Expand Up @@ -119,6 +121,9 @@ func TestOpenAndReload(t *testing.T) {
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
},
})

db.AddRejectedQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", fmt.Errorf("Reloading schema engine should query tables with size information"))

db.MockQueriesForTable("test_table_03", &sqltypes.Result{
Fields: []*querypb.Field{{
Name: "pk1",
Expand Down Expand Up @@ -174,6 +179,15 @@ func TestOpenAndReload(t *testing.T) {

assert.EqualValues(t, secondReadRowsValue, se.innoDbReadRowsCounter.Get())

want["seq"].FileSize = 100
want["seq"].AllocatedSize = 150

want["test_table_01"].FileSize = 100
want["test_table_01"].AllocatedSize = 150

want["test_table_02"].FileSize = 100
want["test_table_02"].AllocatedSize = 150

want["test_table_03"] = &Table{
Name: sqlparser.NewIdentifierCS("test_table_03"),
Fields: []*querypb.Field{{
Expand Down Expand Up @@ -231,6 +245,17 @@ func TestOpenAndReload(t *testing.T) {
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
},
})

db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table_01", false, ""),
mysql.BaseShowTablesRow("test_table_02", false, ""),
mysql.BaseShowTablesRow("test_table_04", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
},
})

db.AddQuery(mysql.BaseShowPrimary, &sqltypes.Result{
Fields: mysql.ShowPrimaryFields,
Rows: [][]sqltypes.Value{
Expand All @@ -254,21 +279,23 @@ func TestReloadWithSwappedTables(t *testing.T) {
db := fakesqldb.New(t)
defer db.Close()
schematest.AddDefaultQueries(db)
db.AddQueryPattern(baseShowTablesPattern,
&sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
RowsAffected: 0,
InsertID: 0,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table_01", false, ""),
mysql.BaseShowTablesRow("test_table_02", false, ""),
mysql.BaseShowTablesRow("test_table_03", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
},
SessionStateChanges: "",
StatusFlags: 0,
})

db.RejectQueryPattern(baseShowTablesPattern, "Opening schema engine should query tables without size information")

db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
RowsAffected: 0,
InsertID: 0,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table_01", false, ""),
mysql.BaseShowTablesRow("test_table_02", false, ""),
mysql.BaseShowTablesRow("test_table_03", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
},
SessionStateChanges: "",
StatusFlags: 0,
})
firstReadRowsValue := 12
AddFakeInnoDBReadRowsResult(db, firstReadRowsValue)

Expand Down Expand Up @@ -322,6 +349,22 @@ func TestReloadWithSwappedTables(t *testing.T) {
})
err := se.Reload(context.Background())
require.NoError(t, err)

want["msg"].FileSize = 100
want["msg"].AllocatedSize = 150

want["seq"].FileSize = 100
want["seq"].AllocatedSize = 150

want["test_table_01"].FileSize = 100
want["test_table_01"].AllocatedSize = 150

want["test_table_02"].FileSize = 100
want["test_table_02"].AllocatedSize = 150

want["test_table_03"].FileSize = 100
want["test_table_03"].AllocatedSize = 150

want["test_table_04"] = &Table{
Name: sqlparser.NewIdentifierCS("test_table_04"),
Fields: []*querypb.Field{{
Expand Down Expand Up @@ -421,7 +464,7 @@ func TestOpenFailedDueToExecErr(t *testing.T) {
defer db.Close()
schematest.AddDefaultQueries(db)
want := "injected error"
db.RejectQueryPattern(baseShowTablesPattern, want)
db.AddRejectedQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", fmt.Errorf(want))
se := newEngine(1*time.Second, 1*time.Second, 0, db)
err := se.Open()
if err == nil || !strings.Contains(err.Error(), want) {
Expand All @@ -436,7 +479,7 @@ func TestOpenFailedDueToLoadTableErr(t *testing.T) {
db := fakesqldb.New(t)
defer db.Close()
schematest.AddDefaultQueries(db)
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table", false, ""),
Expand Down Expand Up @@ -471,7 +514,7 @@ func TestOpenNoErrorDueToInvalidViews(t *testing.T) {
db := fakesqldb.New(t)
defer db.Close()
schematest.AddDefaultQueries(db)
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("foo_view", true, "VIEW"),
Expand Down Expand Up @@ -529,7 +572,7 @@ func TestSchemaEngineCloseTickRace(t *testing.T) {
db := fakesqldb.New(t)
defer db.Close()
schematest.AddDefaultQueries(db)
db.AddQueryPattern(baseShowTablesPattern,
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
&sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
RowsAffected: 0,
Expand Down Expand Up @@ -604,8 +647,8 @@ func initialSchema() map[string]*Table {
}},
PKColumns: []int{0},
CreateTime: 1427325875,
FileSize: 0x64,
AllocatedSize: 0x96,
FileSize: 0,
AllocatedSize: 0,
},
"test_table_02": {
Name: sqlparser.NewIdentifierCS("test_table_02"),
Expand All @@ -615,8 +658,8 @@ func initialSchema() map[string]*Table {
}},
PKColumns: []int{0},
CreateTime: 1427325875,
FileSize: 0x64,
AllocatedSize: 0x96,
FileSize: 0,
AllocatedSize: 0,
},
"test_table_03": {
Name: sqlparser.NewIdentifierCS("test_table_03"),
Expand All @@ -626,8 +669,8 @@ func initialSchema() map[string]*Table {
}},
PKColumns: []int{0},
CreateTime: 1427325875,
FileSize: 0x64,
AllocatedSize: 0x96,
FileSize: 0,
AllocatedSize: 0,
},
"seq": {
Name: sqlparser.NewIdentifierCS("seq"),
Expand All @@ -647,8 +690,8 @@ func initialSchema() map[string]*Table {
}},
PKColumns: []int{0},
CreateTime: 1427325875,
FileSize: 0x64,
AllocatedSize: 0x96,
FileSize: 0,
AllocatedSize: 0,
SequenceInfo: &SequenceInfo{},
},
"msg": {
Expand All @@ -675,8 +718,8 @@ func initialSchema() map[string]*Table {
}},
PKColumns: []int{0},
CreateTime: 1427325875,
FileSize: 0x64,
AllocatedSize: 0x96,
FileSize: 0,
AllocatedSize: 0,
MessageInfo: &MessageInfo{
Fields: []*querypb.Field{{
Name: "id",
Expand Down

0 comments on commit ed0da79

Please sign in to comment.