Skip to content

Commit

Permalink
Improve e2e and unit test setups
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jan 12, 2025
1 parent c9e28e9 commit b94eb40
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
12 changes: 5 additions & 7 deletions go/test/endtoend/vreplication/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ import (
// default collation as it has to work across versions and the 8.0 default does not exist in 5.7.
var (
// All standard user tables should have a primary key and at least one secondary key.
customerTypes = []string{"'individual'", "'soho'", "'enterprise'"}
customerTable = fmt.Sprintf(`create table customer(cid int auto_increment, name varchar(128) collate utf8mb4_bin, meta json default null,
customerTypes = []string{"'individual'", "'soho'", "'enterprise'"}
customerTableTemplate = `create table customer(cid int auto_increment, name varchar(128) collate utf8mb4_bin, meta json default null,
industryCategory varchar(100) generated always as (json_extract(meta, _utf8mb4'$.industry')) virtual, typ enum(%s),
sport set('football','cricket','baseball'), ts timestamp not null default current_timestamp, bits bit(2) default b'11', date1 datetime not null default '0000-00-00 00:00:00',
date2 datetime not null default '2021-00-01 00:00:00', dec80 decimal(8,0), blb blob, primary key(cid,typ), key(name)) CHARSET=utf8mb4`, strings.Join(customerTypes, ","))
date2 datetime not null default '2021-00-01 00:00:00', dec80 decimal(8,0), blb blob, primary key(%s), key(name)) CHARSET=utf8mb4`
customerTable = fmt.Sprintf(customerTableTemplate, strings.Join(customerTypes, ","), "cid,typ" /* PK columns */)
// customerTableModifiedPK has a PK on (cid) vs (cid,typ).
customerTableModifiedPK = fmt.Sprintf(`create table customer(cid int auto_increment, name varchar(128) collate utf8mb4_bin, meta json default null,
industryCategory varchar(100) generated always as (json_extract(meta, _utf8mb4'$.industry')) virtual, typ enum(%s),
sport set('football','cricket','baseball'), ts timestamp not null default current_timestamp, bits bit(2) default b'11', date1 datetime,
date2 datetime, dec80 decimal(8,0), blb blob, primary key(cid), key(name)) CHARSET=utf8mb4`, strings.Join(customerTypes, ","))
customerTableModifiedPK = fmt.Sprintf(customerTableTemplate, strings.Join(customerTypes, ","), "cid" /* PK columns */)

initialProductSchema = fmt.Sprintf(`
create table product(pid int, description varbinary(128), date1 datetime not null default '0000-00-00 00:00:00', date2 datetime not null default '2021-00-01 00:00:00', primary key(pid), key(date1,date2)) CHARSET=utf8mb4;
Expand Down
4 changes: 4 additions & 0 deletions go/test/endtoend/vreplication/vdiff2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ func TestVDiff2(t *testing.T) {
// Pre-create the customer table on the target keyspace, with the primary key on
// (cid) vs (cid,typ) on the source. This confirms that we are able to properly
// diff the table when the source and target have a different PK definition.
// Remove the 0 date restrictions as the customer table uses them in its DEFAULTs.
execVtgateQuery(t, vtgateConn, targetKs, "set @@session.sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'")
execVtgateQuery(t, vtgateConn, targetKs, customerTableModifiedPK)
// Set the sql_mode back to the default.
execVtgateQuery(t, vtgateConn, targetKs, "set @@session.sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'")

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
32 changes: 17 additions & 15 deletions go/vt/vttablet/tabletmanager/vdiff/table_differ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ import (
)

func TestUpdateTableProgress(t *testing.T) {
wd := &workflowDiffer{
ct: &controller{
id: 1,
TableDiffRowCounts: stats.NewCountersWithSingleLabel("", "", "Rows"),
},
opts: &tabletmanagerdatapb.VDiffOptions{
CoreOptions: &tabletmanagerdatapb.VDiffCoreOptions{
MaxDiffSeconds: 100,
},
},
}
table := &tabletmanagerdatapb.TableDefinition{
Name: "test",
}
dr := &DiffReport{
TableName: "test",
TableName: table.Name,
ProcessedRows: 1e9,
}
queryTemplate := `update _vt.vdiff_table set rows_compared = 1000000000, lastpk = '%s', report = '{"TableName":"test","ProcessedRows":1000000000,"MatchingRows":0,"MismatchedRows":0,"ExtraRowsSource":0,"ExtraRowsTarget":0}' where vdiff_id = 1 and table_name = 'test'`
Expand Down Expand Up @@ -98,20 +112,8 @@ func TestUpdateTableProgress(t *testing.T) {
dbc := binlogplayer.NewMockDBClient(t)
dbc.ExpectRequest(fmt.Sprintf(queryTemplate, tc.expectedLastPK), &sqltypes.Result{}, nil)
td := &tableDiffer{
wd: &workflowDiffer{
ct: &controller{
id: 1,
TableDiffRowCounts: stats.NewCountersWithSingleLabel("", "", "Rows"),
},
opts: &tabletmanagerdatapb.VDiffOptions{
CoreOptions: &tabletmanagerdatapb.VDiffCoreOptions{
MaxDiffSeconds: 100,
},
},
},
table: &tabletmanagerdatapb.TableDefinition{
Name: "test",
},
wd: wd,
table: table,
tablePlan: &tablePlan{
pkCols: tc.pkCols,
sourcePkCols: tc.sourcePkCols,
Expand Down

0 comments on commit b94eb40

Please sign in to comment.