Skip to content

Commit

Permalink
fix some executor tests
Browse files Browse the repository at this point in the history
Signed-off-by: deepthi <deepthi@planetscale.com>
  • Loading branch information
deepthi committed Jan 19, 2022
1 parent 1823401 commit 6d885cd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 43 deletions.
1 change: 1 addition & 0 deletions go/vt/discovery/fake_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (fhc *FakeHealthCheck) Reset() {
defer fhc.mu.Unlock()

fhc.items = make(map[string]*fhcItem)
fhc.currentTabletUID.Set(0)
}

// AddFakeTablet inserts a fake entry into FakeHealthCheck.
Expand Down
78 changes: 39 additions & 39 deletions go/vt/vtgate/executor_dml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,45 @@ func TestUpdateEqual(t *testing.T) {
assertQueries(t, sbclookup, wantQueries)
}

func TestUpdateEqualWithWriteOnlyLookupUniqueVindex(t *testing.T) {
res := []*sqltypes.Result{sqltypes.MakeTestResult(
sqltypes.MakeTestFields("id|wo_lu_col|lu_col|t2_lu_vdx", "int64|int64|int64|int64"),
"1|2|1|0",
)}
executor, sbc1, sbc2, sbcLookup := createCustomExecutorSetValues(executorVSchema, res)

_, err := executorExec(executor, "update t2_wo_lookup set lu_col = 5 where wo_lu_col = 2", nil)
require.NoError(t, err)
wantQueries := []*querypb.BoundQuery{
{
Sql: "select id, wo_lu_col, lu_col, lu_col = 5 from t2_wo_lookup where wo_lu_col = 2 for update",
BindVariables: map[string]*querypb.BindVariable{},
}, {
Sql: "update t2_wo_lookup set lu_col = 5 where wo_lu_col = 2",
BindVariables: map[string]*querypb.BindVariable{},
}}

assertQueries(t, sbc1, wantQueries)
assertQueries(t, sbc2, wantQueries)

bq1 := &querypb.BoundQuery{
Sql: "delete from lu_idx where lu_col = :lu_col and keyspace_id = :keyspace_id",
BindVariables: map[string]*querypb.BindVariable{
"keyspace_id": sqltypes.Uint64BindVariable(1),
"lu_col": sqltypes.Int64BindVariable(1),
},
}
bq2 := &querypb.BoundQuery{
Sql: "insert into lu_idx(lu_col, keyspace_id) values (:lu_col_0, :keyspace_id_0)",
BindVariables: map[string]*querypb.BindVariable{
"keyspace_id_0": sqltypes.Uint64BindVariable(1),
"lu_col_0": sqltypes.Int64BindVariable(5),
},
}
lookWant := []*querypb.BoundQuery{bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2}
assertQueries(t, sbcLookup, lookWant)
}

func TestUpdateMultiOwned(t *testing.T) {
vschema := `
{
Expand Down Expand Up @@ -434,45 +473,6 @@ func TestDeleteScatter(t *testing.T) {
assertQueries(t, sbc2, wantQueries)
}

func TestUpdateEqualWithWriteOnlyLookupUniqueVindex(t *testing.T) {
res := []*sqltypes.Result{sqltypes.MakeTestResult(
sqltypes.MakeTestFields("id|wo_lu_col|lu_col|t2_lu_vdx", "int64|int64|int64|int64"),
"1|2|1|0",
)}
executor, sbc1, sbc2, sbcLookup := createCustomExecutorSetValues(executorVSchema, res)

_, err := executorExec(executor, "update t2_wo_lookup set lu_col = 5 where wo_lu_col = 2", nil)
require.NoError(t, err)
wantQueries := []*querypb.BoundQuery{
{
Sql: "select id, wo_lu_col, lu_col, lu_col = 5 from t2_wo_lookup where wo_lu_col = 2 for update",
BindVariables: map[string]*querypb.BindVariable{},
}, {
Sql: "update t2_wo_lookup set lu_col = 5 where wo_lu_col = 2",
BindVariables: map[string]*querypb.BindVariable{},
}}

assertQueries(t, sbc1, wantQueries)
assertQueries(t, sbc2, wantQueries)

bq1 := &querypb.BoundQuery{
Sql: "delete from lu_idx where lu_col = :lu_col and keyspace_id = :keyspace_id",
BindVariables: map[string]*querypb.BindVariable{
"keyspace_id": sqltypes.Uint64BindVariable(1),
"lu_col": sqltypes.Int64BindVariable(1),
},
}
bq2 := &querypb.BoundQuery{
Sql: "insert into lu_idx(lu_col, keyspace_id) values (:lu_col_0, :keyspace_id_0)",
BindVariables: map[string]*querypb.BindVariable{
"keyspace_id_0": sqltypes.Uint64BindVariable(1),
"lu_col_0": sqltypes.Int64BindVariable(5),
},
}
lookWant := []*querypb.BoundQuery{bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2, bq1, bq2}
assertQueries(t, sbcLookup, lookWant)
}

func TestUpdateEqualWithMultipleLookupVindex(t *testing.T) {
executor, sbc1, sbc2, sbcLookup := createCustomExecutorSetValues(executorVSchema, nil)

Expand Down
14 changes: 13 additions & 1 deletion go/vt/vtgate/executor_framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func createExecutorEnv() (executor *Executor, sbc1, sbc2, sbclookup *sandboxconn
_ = hc.AddTestTablet(cell, "c0-e0", 1, "TestExecutor", "c0-e0", topodatapb.TabletType_PRIMARY, true, 1, nil)
_ = hc.AddTestTablet(cell, "e0-", 1, "TestExecutor", "e0-", topodatapb.TabletType_PRIMARY, true, 1, nil)
// Below is needed so that SendAnyWherePlan doesn't fail
_ = hc.AddTestTablet(cell, "e0-", 1, "TestXBadVSchema", "-20", topodatapb.TabletType_PRIMARY, true, 1, nil)
_ = hc.AddTestTablet(cell, "random", 1, "TestXBadVSchema", "-20", topodatapb.TabletType_PRIMARY, true, 1, nil)

createSandbox(KsTestUnsharded)
_ = topo.NewShardInfo(KsTestUnsharded, "0", &topodatapb.Shard{}, nil)
Expand Down Expand Up @@ -489,6 +489,10 @@ func createExecutorEnv() (executor *Executor, sbc1, sbc2, sbclookup *sandboxconn
executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false)

key.AnyShardPicker = DestinationAnyShardPickerFirstShard{}
// create a new session each time so that ShardSessions don't get re-used across tests
primarySession = &vtgatepb.Session{
TargetString: "@primary",
}
return executor, sbc1, sbc2, sbclookup
}

Expand All @@ -507,6 +511,10 @@ func createCustomExecutor(vschema string) (executor *Executor, sbc1, sbc2, sbclo
getSandbox(KsTestUnsharded).VSchema = unshardedVSchema

executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false)
// create a new session each time so that ShardSessions don't get re-used across tests
primarySession = &vtgatepb.Session{
TargetString: "@primary",
}
return executor, sbc1, sbc2, sbclookup
}

Expand All @@ -532,6 +540,10 @@ func createCustomExecutorSetValues(vschema string, values []*sqltypes.Result) (e
getSandbox(KsTestUnsharded).VSchema = unshardedVSchema

executor = NewExecutor(context.Background(), serv, cell, resolver, false, false, testBufferSize, cache.DefaultConfig, nil, false)
// create a new session each time so that ShardSessions don't get re-used across tests
primarySession = &vtgatepb.Session{
TargetString: "@primary",
}
return executor, sbcs[0], sbcs[1], sbclookup
}

Expand Down
9 changes: 6 additions & 3 deletions go/vt/vtgate/vtgate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ var executeOptions = &querypb.ExecuteOptions{
IncludedFields: querypb.ExecuteOptions_TYPE_ONLY,
}

var primarySession = &vtgatepb.Session{
TargetString: "@primary",
}
var primarySession *vtgatepb.Session

func init() {
getSandbox(KsTestUnsharded).VSchema = `
Expand Down Expand Up @@ -300,6 +298,11 @@ func testErrorPropagation(t *testing.T, sbcs []*sandboxconn.SandboxConn, before
func TestErrorPropagation(t *testing.T) {
createSandbox(KsTestUnsharded)
hcVTGateTest.Reset()
// create a new session each time so that ShardSessions don't get re-used across tests
primarySession = &vtgatepb.Session{
TargetString: "@primary",
}

sbcm := hcVTGateTest.AddTestTablet("aa", "1.1.1.1", 1001, KsTestUnsharded, "0", topodatapb.TabletType_PRIMARY, true, 1, nil)
sbcrdonly := hcVTGateTest.AddTestTablet("aa", "1.1.1.2", 1001, KsTestUnsharded, "0", topodatapb.TabletType_RDONLY, true, 1, nil)
sbcs := []*sandboxconn.SandboxConn{
Expand Down

0 comments on commit 6d885cd

Please sign in to comment.