Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Oct 4, 2023
1 parent ffb1ab1 commit bcb37fd
Showing 1 changed file with 101 additions and 73 deletions.
174 changes: 101 additions & 73 deletions go/vt/vtctl/workflow/materializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func TestMoveTablesNoRoutingRules(t *testing.T) {

func TestCreateLookupVindexFull(t *testing.T) {
ms := &vtctldatapb.MaterializeSettings{
Workflow: "lookup_vdx",
Workflow: "lookup",
SourceKeyspace: "sourceks",
TargetKeyspace: "targetks",
}
Expand All @@ -600,7 +600,7 @@ func TestCreateLookupVindexFull(t *testing.T) {
"v": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.lookup_vdx",
"table": "targetks.lookup",
"from": "c1",
"to": "c2",
},
Expand Down Expand Up @@ -660,9 +660,9 @@ func TestCreateLookupVindexFull(t *testing.T) {

env.tmc.expectVRQuery(100, mzCheckJournal, &sqltypes.Result{})
env.tmc.expectVRQuery(200, mzSelectFrozenQuery, &sqltypes.Result{})
env.tmc.expectVRQuery(200, "/CREATE TABLE `lookup_vdx`", &sqltypes.Result{})
env.tmc.expectVRQuery(200, "/CREATE TABLE `lookup`", &sqltypes.Result{})
env.tmc.expectVRQuery(200, insertPrefix, &sqltypes.Result{})
env.tmc.expectVRQuery(200, "update _vt.vreplication set state='Running' where db_name='vt_targetks' and workflow='lookup_vdx'", &sqltypes.Result{})
env.tmc.expectVRQuery(200, "update _vt.vreplication set state='Running' where db_name='vt_targetks' and workflow='lookup'", &sqltypes.Result{})

req := &vtctldatapb.LookupVindexCreateRequest{
Workflow: ms.Workflow,
Expand All @@ -684,7 +684,7 @@ func TestCreateLookupVindexFull(t *testing.T) {
"v": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.lookup_vdx",
"table": "targetks.lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
Expand All @@ -710,7 +710,7 @@ func TestCreateLookupVindexFull(t *testing.T) {

wantvschema = &vschemapb.Keyspace{
Tables: map[string]*vschemapb.Table{
"lookup_vdx": {},
"lookup": {},
},
}
vschema, err = env.topoServ.GetVSchema(ctx, ms.TargetKeyspace)
Expand Down Expand Up @@ -2164,7 +2164,7 @@ func TestCreateLookupVindexFailures(t *testing.T) {
for _, tcase := range testcases {
t.Run(tcase.description, func(t *testing.T) {
req := &vtctldatapb.LookupVindexCreateRequest{
Workflow: "lookup_vdx",
Workflow: "lookup",
Keyspace: ms.TargetKeyspace,
Vindex: tcase.input,
}
Expand Down Expand Up @@ -2253,109 +2253,138 @@ func TestExternalizeLookupVindex(t *testing.T) {
unownedStopped := sqltypes.MakeTestResult(fields, "2|Stopped|Stopped after copy|"+unownedSourceStopAfterCopy)

testcases := []struct {
request *vtctldatapb.LookupVindexExternalizeRequest
vrResponse *sqltypes.Result
err string
expectDelete bool
request *vtctldatapb.LookupVindexExternalizeRequest
vrResponse *sqltypes.Result
err string
expectedVschema *vschemapb.Keyspace
expectDelete bool
}{
{
request: &vtctldatapb.LookupVindexExternalizeRequest{
Name: "unowned_lookup_vdx",
Keyspace: ms.TargetKeyspace,
Vindex: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"unowned_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.unowned_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
Name: "owned_lookup",
Keyspace: ms.SourceKeyspace,
TargetKeyspace: ms.TargetKeyspace,
},
vrResponse: ownedStopped,
expectedVschema: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"owned_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.owned_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
Owner: "t1",
},
},
},
expectDelete: true,
},
{
request: &vtctldatapb.LookupVindexExternalizeRequest{
Name: "unowned_lookup",
Keyspace: ms.SourceKeyspace,
TargetKeyspace: ms.TargetKeyspace,
},
vrResponse: unownedStopped,
err: "is not in Running state",
expectedVschema: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"unowned_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.unowned_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
},
},
},
err: "is not in Running state",
},
{
request: &vtctldatapb.LookupVindexExternalizeRequest{
Workflow: "owned_lookup_vdx",
Keyspace: ms.SourceKeyspace,
Vindex: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"owned_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.owned_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
Owner: "t1",
Name: "owned_lookup",
Keyspace: ms.SourceKeyspace,
TargetKeyspace: ms.TargetKeyspace,
},
vrResponse: ownedRunning,
expectedVschema: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"owned_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.owned_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
Owner: "t1",
},
},
},
vrResponse: ownedRunning,
expectDelete: true,
},
{
request: &vtctldatapb.LookupVindexExternalizeRequest{
Workflow: "unowned_lookup_vdx",
Keyspace: ms.SourceKeyspace,
Vindex: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"unowned_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.unowned_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
Name: "unowned_lookup",
Keyspace: ms.SourceKeyspace,
TargetKeyspace: ms.TargetKeyspace,
},
vrResponse: unownedRunning,
expectedVschema: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"unowned_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.unowned_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
},
},
},
vrResponse: unownedRunning,
},
{
request: &vtctldatapb.LookupVindexExternalizeRequest{
Workflow: "absent_lookup_vdx",
Keyspace: ms.SourceKeyspace,
Vindex: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"absent_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.absent_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
Name: "absent_lookup",
Keyspace: ms.SourceKeyspace,
TargetKeyspace: ms.TargetKeyspace,
},
expectedVschema: &vschemapb.Keyspace{
Sharded: false,
Vindexes: map[string]*vschemapb.Vindex{
"absent_lookup": {
Type: "lookup_unique",
Params: map[string]string{
"table": "targetks.absent_lookup",
"from": "c1",
"to": "c2",
"write_only": "true",
},
},
},
},
err: "vindex absent_lookup not found in sourceks vschema",
err: "vindex absent_lookup not found in the sourceks keyspace",
},
}
for _, tcase := range testcases {
t.Run(tcase.request.Workflow, func(t *testing.T) {
t.Run(tcase.request.Name, func(t *testing.T) {
// Resave the source schema for every iteration.
err := env.topoServ.SaveVSchema(ctx, tcase.request.Keyspace, sourceVschema)
require.NoError(t, err)
err = env.topoServ.RebuildSrvVSchema(ctx, []string{env.cell})
require.NoError(t, err)

validationQuery := fmt.Sprintf("select id, state, message, source from _vt.vreplication where workflow='%s' and db_name='vt_%s'",
tcase.request.Workflow, ms.TargetKeyspace)
tcase.request.Name, ms.TargetKeyspace)
env.tmc.expectVRQuery(200, validationQuery, tcase.vrResponse)
env.tmc.expectVRQuery(210, validationQuery, tcase.vrResponse)

Expand All @@ -2377,9 +2406,8 @@ func TestExternalizeLookupVindex(t *testing.T) {

aftervschema, err := env.topoServ.GetVSchema(ctx, ms.SourceKeyspace)
require.NoError(t, err)
vindexName := strings.Replace(tcase.request.Workflow, "_vdx", "", 1)
vindex := aftervschema.Vindexes[vindexName]
require.NotNil(t, vindex, "vindex %s not found in vschema", vindexName)
vindex := aftervschema.Vindexes[tcase.request.Name]
require.NotNil(t, vindex, "vindex %s not found in vschema", tcase.request.Name)
require.NotContains(t, vindex.Params, "write_only", tcase.request)
})
}
Expand Down

0 comments on commit bcb37fd

Please sign in to comment.