Skip to content

Commit 8393dea

Browse files
committed
test: Mock query for failing tests
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
1 parent 10ee600 commit 8393dea

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

go/vt/vttablet/tabletmanager/framework_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ func (tmc *fakeTMClient) VReplicationExec(ctx context.Context, tablet *topodatap
480480
}
481481
for qry, res := range tmc.vreQueries[int(tablet.Alias.Uid)] {
482482
if strings.HasPrefix(qry, "/") {
483-
re := regexp.MustCompile(qry)
484-
if re.MatchString(qry) {
483+
re := regexp.MustCompile(qry[1:])
484+
if re.MatchString(query) {
485485
return res, nil
486486
}
487487
}

go/vt/vttablet/tabletmanager/rpc_vreplication_test.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ func TestCreateVReplicationWorkflow(t *testing.T) {
128128
ws := workflow.NewServer(vtenv.NewTestEnv(), tenv.ts, tenv.tmc)
129129

130130
tests := []struct {
131-
name string
132-
req *vtctldatapb.MoveTablesCreateRequest
133-
schema *tabletmanagerdatapb.SchemaDefinition
134-
query string
131+
name string
132+
req *vtctldatapb.MoveTablesCreateRequest
133+
schema *tabletmanagerdatapb.SchemaDefinition
134+
query string
135+
selectTableQuery string
135136
}{
136137
{
137138
name: "defaults",
@@ -144,6 +145,7 @@ func TestCreateVReplicationWorkflow(t *testing.T) {
144145
},
145146
query: fmt.Sprintf(`%s values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"}}', '', 0, 0, '%s', '', now(), 0, 'Stopped', '%s', 1, 0, 0, '{}')`,
146147
insertVReplicationPrefix, wf, sourceKs, shard, tenv.cells[0], tenv.dbName),
148+
selectTableQuery: "(select 't1' from t1 limit 1)",
147149
},
148150
{
149151
name: "all values",
@@ -179,6 +181,7 @@ func TestCreateVReplicationWorkflow(t *testing.T) {
179181
},
180182
query: fmt.Sprintf(`%s values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"}} on_ddl:EXEC stop_after_copy:true source_time_zone:"EDT" target_time_zone:"UTC"', '', 0, 0, '%s', '', now(), 0, 'Stopped', '%s', 1, 0, 1, '{}')`,
181183
insertVReplicationPrefix, wf, sourceKs, shard, tenv.cells[0], tenv.dbName),
184+
selectTableQuery: "(select 't1' from t1 limit 1)",
182185
},
183186
{
184187
name: "binlog source order with include",
@@ -219,6 +222,7 @@ func TestCreateVReplicationWorkflow(t *testing.T) {
219222
},
220223
query: fmt.Sprintf(`%s values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"} rules:{match:"wut" filter:"select * from wut"} rules:{match:"zt" filter:"select * from zt"}} on_ddl:EXEC stop_after_copy:true source_time_zone:"EDT" target_time_zone:"UTC"', '', 0, 0, '%s', '', now(), 0, 'Stopped', '%s', 1, 0, 1, '{}')`,
221224
insertVReplicationPrefix, wf, sourceKs, shard, tenv.cells[0], tenv.dbName),
225+
selectTableQuery: "/.*union all.*union all.*",
222226
},
223227
{
224228
name: "binlog source order with all-tables",
@@ -259,6 +263,7 @@ func TestCreateVReplicationWorkflow(t *testing.T) {
259263
},
260264
query: fmt.Sprintf(`%s values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"} rules:{match:"wut" filter:"select * from wut"} rules:{match:"zt" filter:"select * from zt"}} on_ddl:EXEC stop_after_copy:true source_time_zone:"EDT" target_time_zone:"UTC"', '', 0, 0, '%s', '', now(), 0, 'Stopped', '%s', 1, 0, 1, '{}')`,
261265
insertVReplicationPrefix, wf, sourceKs, shard, tenv.cells[0], tenv.dbName),
266+
selectTableQuery: "/.*union all.*union all.*",
262267
},
263268
}
264269

@@ -289,6 +294,7 @@ func TestCreateVReplicationWorkflow(t *testing.T) {
289294
targetTablet.vrdbClient.ExpectRequest(fmt.Sprintf(readAllWorkflows, tenv.dbName, ""), &sqltypes.Result{}, nil)
290295
targetTablet.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecar.GetIdentifier()), &sqltypes.Result{}, nil)
291296
targetTablet.vrdbClient.ExpectRequest(tt.query, &sqltypes.Result{}, errShortCircuit)
297+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, tt.selectTableQuery, &sqltypes.Result{})
292298
_, err := ws.MoveTablesCreate(ctx, tt.req)
293299
tenv.tmc.tablets[targetTabletUID].vrdbClient.Wait()
294300
require.ErrorIs(t, err, errShortCircuit)
@@ -712,6 +718,7 @@ func TestMoveTablesSharded(t *testing.T) {
712718
fmt.Sprintf("%s|%d|%s|%s|NULL|0|0|||1686577659|0|Running||%s|1||0|0|0||0|1|{}", wf, vreplID, bls, position, targetKs),
713719
), nil)
714720
tenv.tmc.setVReplicationExecResults(ftc.tablet, fmt.Sprintf(getLatestCopyState, vreplID, vreplID), &sqltypes.Result{})
721+
tenv.tmc.setVReplicationExecResults(ftc.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
715722
}
716723

717724
// We use the tablet's UID in the mocked results for the max value used on each target shard.
@@ -1334,6 +1341,7 @@ func TestSourceShardSelection(t *testing.T) {
13341341
tt := targetTablets[uid]
13351342
tt.vrdbClient.ExpectRequest(fmt.Sprintf("use %s", sidecar.GetIdentifier()), &sqltypes.Result{}, nil)
13361343
tt.vrdbClient.ExpectRequest(fmt.Sprintf(readAllWorkflows, tenv.dbName, ""), &sqltypes.Result{}, nil)
1344+
tenv.tmc.setVReplicationExecResults(tt.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
13371345
for i, sourceShard := range streams {
13381346
var err error
13391347
if i == len(streams)-1 {
@@ -1484,6 +1492,7 @@ func TestFailedMoveTablesCreateCleanup(t *testing.T) {
14841492
fmt.Sprintf(deleteWorkflow, targetKs, wf),
14851493
&sqltypes.Result{RowsAffected: 1},
14861494
)
1495+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
14871496

14881497
// Save the current target vschema.
14891498
vs, err := tenv.ts.GetVSchema(ctx, targetKs)
@@ -2112,6 +2121,7 @@ func TestMaterializerOneToOne(t *testing.T) {
21122121
fmt.Sprintf(` values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"} rules:{match:"t2" filter:"select * from t3"} rules:{match:"t4"}}', '', 0, 0, '%s', 'primary,rdonly', now(), 0, 'Stopped', '%s', 0, 0, 0, '{}')`,
21132122
wf, sourceKs, shard, tenv.cells[0], tenv.dbName)
21142123
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{}, errShortCircuit)
2124+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "/.*union all.*union all.*", &sqltypes.Result{})
21152125

21162126
err := ws.Materialize(ctx, ms)
21172127
targetTablet.vrdbClient.Wait()
@@ -2198,6 +2208,7 @@ func TestMaterializerManyToOne(t *testing.T) {
21982208
} else {
21992209
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{InsertID: uint64(vreplID)}, errShortCircuit)
22002210
}
2211+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "/.*union all.*", &sqltypes.Result{})
22012212
}
22022213

22032214
err := ws.Materialize(ctx, ms)
@@ -2300,6 +2311,7 @@ func TestMaterializerOneToMany(t *testing.T) {
23002311
} else {
23012312
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{InsertID: uint64(vreplID)}, errShortCircuit)
23022313
}
2314+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
23032315
}
23042316

23052317
err = ws.Materialize(ctx, ms)
@@ -2408,6 +2420,7 @@ func TestMaterializerManyToMany(t *testing.T) {
24082420
fmt.Sprintf("%d|%s", vreplID, bls),
24092421
), nil)
24102422
}
2423+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
24112424
}
24122425
}
24132426

@@ -2516,6 +2529,7 @@ func TestMaterializerMulticolumnVindex(t *testing.T) {
25162529
} else {
25172530
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{InsertID: uint64(vreplID)}, errShortCircuit)
25182531
}
2532+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
25192533
}
25202534

25212535
err = ws.Materialize(ctx, ms)
@@ -2587,6 +2601,7 @@ func TestMaterializerDeploySchema(t *testing.T) {
25872601
fmt.Sprintf(` values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"} rules:{match:"t2" filter:"select * from t3"}}', '', 0, 0, '%s', 'primary,rdonly', now(), 0, 'Stopped', '%s', 0, 0, 0, '{}')`,
25882602
wf, sourceKs, shard, tenv.cells[0], tenv.dbName)
25892603
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{}, errShortCircuit)
2604+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
25902605

25912606
err := ws.Materialize(ctx, ms)
25922607
targetTablet.vrdbClient.Wait()
@@ -2657,6 +2672,7 @@ func TestMaterializerCopySchema(t *testing.T) {
26572672
fmt.Sprintf(` values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"} rules:{match:"t2" filter:"select * from t3"}}', '', 0, 0, '%s', 'primary,rdonly', now(), 0, 'Stopped', '%s', 0, 0, 0, '{}')`,
26582673
wf, sourceKs, shard, tenv.cells[0], tenv.dbName)
26592674
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{}, errShortCircuit)
2675+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "/.*union all.*", &sqltypes.Result{})
26602676

26612677
err := ws.Materialize(ctx, ms)
26622678
targetTablet.vrdbClient.Wait()
@@ -2763,6 +2779,7 @@ func TestMaterializerExplicitColumns(t *testing.T) {
27632779
} else {
27642780
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{InsertID: uint64(vreplID)}, errShortCircuit)
27652781
}
2782+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
27662783
}
27672784

27682785
err = ws.Materialize(ctx, ms)
@@ -2870,6 +2887,7 @@ func TestMaterializerRenamedColumns(t *testing.T) {
28702887
} else {
28712888
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{InsertID: uint64(vreplID)}, errShortCircuit)
28722889
}
2890+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
28732891
}
28742892

28752893
err = ws.Materialize(ctx, ms)
@@ -2932,6 +2950,7 @@ func TestMaterializerStopAfterCopy(t *testing.T) {
29322950
fmt.Sprintf(` values ('%s', 'keyspace:"%s" shard:"%s" filter:{rules:{match:"t1" filter:"select * from t1"} rules:{match:"t2" filter:"select * from t3"}} stop_after_copy:true', '', 0, 0, '%s', 'primary,rdonly', now(), 0, 'Stopped', '%s', 0, 0, 0, '{}')`,
29332951
wf, sourceKs, shard, tenv.cells[0], tenv.dbName)
29342952
targetTablet.vrdbClient.ExpectRequest(insert, &sqltypes.Result{}, errShortCircuit)
2953+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "/.*union all.*", &sqltypes.Result{})
29352954

29362955
err := ws.Materialize(ctx, ms)
29372956
targetTablet.vrdbClient.Wait()
@@ -3386,6 +3405,7 @@ func TestMaterializerNoGoodVindex(t *testing.T) {
33863405
targetTablet := targetShards[targetShard]
33873406
addInvariants(targetTablet.vrdbClient, vreplID, sourceTabletUID, position, wf, tenv.cells[0])
33883407
targetTablet.vrdbClient.ExpectRequest(fmt.Sprintf(readAllWorkflows, tenv.dbName, ""), &sqltypes.Result{}, nil)
3408+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
33893409
errs = append(errs, errNoVindex)
33903410
}
33913411

@@ -3461,6 +3481,7 @@ func TestMaterializerComplexVindexExpression(t *testing.T) {
34613481
targetTablet := targetShards[targetShard]
34623482
addInvariants(targetTablet.vrdbClient, vreplID, sourceTabletUID, position, wf, tenv.cells[0])
34633483
targetTablet.vrdbClient.ExpectRequest(fmt.Sprintf(readAllWorkflows, tenv.dbName, ""), &sqltypes.Result{}, nil)
3484+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
34643485
errs = append(errs, errNoVindex)
34653486
}
34663487

@@ -3536,6 +3557,7 @@ func TestMaterializerNoVindexInExpression(t *testing.T) {
35363557
targetTablet := targetShards[targetShard]
35373558
addInvariants(targetTablet.vrdbClient, vreplID, sourceTabletUID, position, wf, tenv.cells[0])
35383559
targetTablet.vrdbClient.ExpectRequest(fmt.Sprintf(readAllWorkflows, tenv.dbName, ""), &sqltypes.Result{}, nil)
3560+
tenv.tmc.setVReplicationExecResults(targetTablet.tablet, "(select 't1' from t1 limit 1)", &sqltypes.Result{})
35393561
errs = append(errs, errNoVindex)
35403562
}
35413563

0 commit comments

Comments
 (0)