Skip to content

Commit

Permalink
test: refactor test
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Dec 20, 2024
1 parent 1c2be73 commit b14f0e8
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions go/vt/vtgate/scatter_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,40 @@ func TestExecuteFailOnAutocommit(t *testing.T) {
func TestFetchLastInsertIDResets(t *testing.T) {
// This test verifies that the FetchLastInsertID flag is reset after a call to ExecuteMultiShard.
ks := "TestFetchLastInsertIDResets"
ctx := utils.LeakCheckContext(t)

createSandbox(ks)
hc := discovery.NewFakeHealthCheck(nil)
sc := newTestScatterConn(ctx, hc, newSandboxForCells(ctx, []string{"aa"}), "aa")
sbc0 := hc.AddTestTablet("aa", "0", 1, ks, "0", topodatapb.TabletType_PRIMARY, true, 1, nil)
sbc1 := hc.AddTestTablet("aa", "1", 1, ks, "1", topodatapb.TabletType_PRIMARY, true, 1, nil)

rss := []*srvtopo.ResolvedShard{{
Target: &querypb.Target{
Keyspace: ks,
Shard: "0",
TabletType: topodatapb.TabletType_PRIMARY,
},
Gateway: sbc0,
}, {
Target: &querypb.Target{
Keyspace: ks,
Shard: "1",
TabletType: topodatapb.TabletType_PRIMARY,
},
Gateway: sbc1,
}}
queries := []*querypb.BoundQuery{{
Sql: "query1",
BindVariables: map[string]*querypb.BindVariable{
"bv0": sqltypes.Int64BindVariable(0),
},
}, {
Sql: "query2",
BindVariables: map[string]*querypb.BindVariable{
"bv1": sqltypes.Int64BindVariable(1),
},
}}
tests := []struct {
name string
initialSessionOpts *querypb.ExecuteOptions
Expand Down Expand Up @@ -148,41 +182,6 @@ func TestFetchLastInsertIDResets(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := utils.LeakCheckContext(t)

createSandbox(ks)
hc := discovery.NewFakeHealthCheck(nil)
sc := newTestScatterConn(ctx, hc, newSandboxForCells(ctx, []string{"aa"}), "aa")
sbc0 := hc.AddTestTablet("aa", "0", 1, ks, "0", topodatapb.TabletType_PRIMARY, true, 1, nil)
sbc1 := hc.AddTestTablet("aa", "1", 1, ks, "1", topodatapb.TabletType_PRIMARY, true, 1, nil)

rss := []*srvtopo.ResolvedShard{{
Target: &querypb.Target{
Keyspace: ks,
Shard: "0",
TabletType: topodatapb.TabletType_PRIMARY,
},
Gateway: sbc0,
}, {
Target: &querypb.Target{
Keyspace: ks,
Shard: "1",
TabletType: topodatapb.TabletType_PRIMARY,
},
Gateway: sbc1,
}}
queries := []*querypb.BoundQuery{{
Sql: "query1",
BindVariables: map[string]*querypb.BindVariable{
"bv0": sqltypes.Int64BindVariable(0),
},
}, {
Sql: "query2",
BindVariables: map[string]*querypb.BindVariable{
"bv1": sqltypes.Int64BindVariable(1),
},
}}

session := econtext.NewSafeSession(nil)
session.Options = tt.initialSessionOpts

Expand Down

0 comments on commit b14f0e8

Please sign in to comment.