-
Notifications
You must be signed in to change notification settings - Fork 2.3k
VReplication: Fix VDiff2 DeleteByUUID Query #13255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,14 @@ package vdiff | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "reflect" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
|
|
||
| "vitess.io/vitess/go/sqltypes" | ||
| tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata" | ||
| vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" | ||
| "vitess.io/vitess/go/vt/vterrors" | ||
|
|
@@ -30,27 +34,64 @@ import ( | |
| func TestPerformVDiffAction(t *testing.T) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
| vdiffenv := newTestVDiffEnv(t) | ||
| defer vdiffenv.close() | ||
| keyspace := "ks" | ||
| workflow := "wf" | ||
| uuid := uuid.New().String() | ||
| tests := []struct { | ||
| name string | ||
| vde *Engine | ||
| req *tabletmanagerdatapb.VDiffRequest | ||
| want *tabletmanagerdatapb.VDiffResponse | ||
| wantErr error | ||
| name string | ||
| vde *Engine | ||
| req *tabletmanagerdatapb.VDiffRequest | ||
| want *tabletmanagerdatapb.VDiffResponse | ||
| expectQueries []string | ||
| wantErr error | ||
| }{ | ||
| { | ||
| name: "engine not open", | ||
| vde: &Engine{isOpen: false}, | ||
| wantErr: vterrors.New(vtrpcpb.Code_UNAVAILABLE, "vdiff engine is closed"), | ||
| }, | ||
| { | ||
| name: "delete by uuid", | ||
| req: &tabletmanagerdatapb.VDiffRequest{ | ||
| Action: string(DeleteAction), | ||
| ActionArg: uuid, | ||
| }, | ||
| expectQueries: []string{ | ||
| fmt.Sprintf(`delete from vd, vdt using _vt.vdiff as vd left join _vt.vdiff_table as vdt on (vd.id = vdt.vdiff_id) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is same as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I intentionally did NOT use the variable as this way I can catch any accidental change to the query (in the variable). |
||
| where vd.vdiff_uuid = %s`, encodeString(uuid)), | ||
| }, | ||
| }, | ||
| { | ||
| name: "delete all", | ||
| req: &tabletmanagerdatapb.VDiffRequest{ | ||
| Action: string(DeleteAction), | ||
| ActionArg: "all", | ||
| Keyspace: keyspace, | ||
| Workflow: workflow, | ||
| }, | ||
| expectQueries: []string{ | ||
| fmt.Sprintf(`delete from vd, vdt, vdl using _vt.vdiff as vd left join _vt.vdiff_table as vdt on (vd.id = vdt.vdiff_id) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is same as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I intentionally did NOT use the variable as this way I can catch any accidental change to the query (in the variable). |
||
| left join _vt.vdiff_log as vdl on (vd.id = vdl.vdiff_id) | ||
| where vd.keyspace = %s and vd.workflow = %s`, encodeString(keyspace), encodeString(workflow)), | ||
| }, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| if tt.vde == nil { | ||
| tt.vde = vdiffenv.vde | ||
| } | ||
| for _, query := range tt.expectQueries { | ||
| vdiffenv.dbClient.ExpectRequest(query, &sqltypes.Result{}, nil) | ||
| } | ||
| got, err := tt.vde.PerformVDiffAction(ctx, tt.req) | ||
| if tt.wantErr != nil && !vterrors.Equals(err, tt.wantErr) { | ||
| t.Errorf("Engine.PerformVDiffAction() error = %v, wantErr %v", err, tt.wantErr) | ||
| return | ||
| } | ||
| if !reflect.DeepEqual(got, tt.want) { | ||
| if tt.want != nil && !reflect.DeepEqual(got, tt.want) { | ||
| t.Errorf("Engine.PerformVDiffAction() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.