Skip to content

Commit 12126f1

Browse files
e2e tests: use t.Context() from testing as context.Context (#19081)
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
1 parent 32b8bd8 commit 12126f1

File tree

82 files changed

+218
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+218
-293
lines changed

go/test/endtoend/cluster/cluster_util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (tablet *Vttablet) ValidateTabletRestart(t *testing.T) {
9595

9696
// GetPrimaryPosition gets the executed replication position of given vttablet
9797
func GetPrimaryPosition(t *testing.T, vttablet Vttablet, hostname string) (string, string) {
98-
ctx := context.Background()
98+
ctx := t.Context()
9999
vtablet := getTablet(vttablet.GrpcPort, hostname)
100100
pos, err := tmClient.PrimaryPosition(ctx, vtablet)
101101
require.Nil(t, err)
@@ -105,7 +105,7 @@ func GetPrimaryPosition(t *testing.T, vttablet Vttablet, hostname string) (strin
105105

106106
// FullStatus gets the full status from the given tablet.
107107
func FullStatus(t *testing.T, vttablet *Vttablet, hostname string) *replicationdatapb.FullStatus {
108-
ctx := context.Background()
108+
ctx := t.Context()
109109
vtablet := getTablet(vttablet.GrpcPort, hostname)
110110
status, err := tmClient.FullStatus(ctx, vtablet)
111111
require.NoError(t, err)

go/test/endtoend/clustertest/add_keyspace_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ This adds sharded keyspace dynamically in this test only and test sql insert, se
1919
package clustertest
2020

2121
import (
22-
"context"
2322
"fmt"
2423
"testing"
2524

26-
"vitess.io/vitess/go/test/endtoend/utils"
27-
28-
"vitess.io/vitess/go/vt/log"
29-
3025
"vitess.io/vitess/go/mysql"
3126
"vitess.io/vitess/go/test/endtoend/cluster"
27+
"vitess.io/vitess/go/test/endtoend/utils"
28+
"vitess.io/vitess/go/vt/log"
3229
)
3330

3431
var (
@@ -71,7 +68,7 @@ func TestAddKeyspace(t *testing.T) {
7168
_ = clusterInstance.VtgateProcess.Setup()
7269
clusterInstance.WaitForTabletsToHealthyInVtgate()
7370

74-
ctx := context.Background()
71+
ctx := t.Context()
7572
vtParams := mysql.ConnParams{
7673
Host: clusterInstance.Hostname,
7774
Port: clusterInstance.VtgateMySQLPort,

go/test/endtoend/clustertest/vtgate_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ This tests select/insert using the unshared keyspace added in main_test
1818
package clustertest
1919

2020
import (
21-
"context"
2221
"encoding/json"
2322
"fmt"
2423
"io"
@@ -27,16 +26,15 @@ import (
2726
"strings"
2827
"testing"
2928

30-
"vitess.io/vitess/go/test/endtoend/utils"
31-
3229
"github.com/stretchr/testify/require"
3330

3431
"vitess.io/vitess/go/mysql"
32+
"vitess.io/vitess/go/test/endtoend/utils"
3533
)
3634

3735
func TestVtgateProcess(t *testing.T) {
3836
verifyVtgateVariables(t, clusterInstance.VtgateProcess.VerifyURL)
39-
ctx := context.Background()
37+
ctx := t.Context()
4038
conn, err := mysql.Connect(ctx, &vtParams)
4139
require.NoError(t, err)
4240
defer conn.Close()

go/test/endtoend/docker/vttestserver_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ limitations under the License.
1717
package docker
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"os"
2322
"testing"
2423

25-
"vitess.io/vitess/go/test/endtoend/cluster"
26-
"vitess.io/vitess/go/test/endtoend/utils"
24+
"github.com/stretchr/testify/require"
2725

2826
"vitess.io/vitess/go/mysql"
29-
30-
"github.com/stretchr/testify/require"
27+
"vitess.io/vitess/go/test/endtoend/cluster"
28+
"vitess.io/vitess/go/test/endtoend/utils"
3129
)
3230

3331
func TestMain(m *testing.M) {
@@ -54,7 +52,7 @@ func TestUnsharded(t *testing.T) {
5452
err = vtest.waitUntilDockerHealthy(10)
5553
require.NoError(t, err)
5654

57-
ctx := context.Background()
55+
ctx := t.Context()
5856
vttestParams := mysql.ConnParams{
5957
Host: "localhost",
6058
Port: vtest.basePort + 3,
@@ -83,7 +81,7 @@ func TestSharded(t *testing.T) {
8381
err = vtest.waitUntilDockerHealthy(10)
8482
require.NoError(t, err)
8583

86-
ctx := context.Background()
84+
ctx := t.Context()
8785
vttestParams := mysql.ConnParams{
8886
Host: "localhost",
8987
Port: vtest.basePort + 3,
@@ -113,7 +111,7 @@ func TestMysqlMaxCons(t *testing.T) {
113111
err = vtest.waitUntilDockerHealthy(10)
114112
require.NoError(t, err)
115113

116-
ctx := context.Background()
114+
ctx := t.Context()
117115
vttestParams := mysql.ConnParams{
118116
Host: "localhost",
119117
Port: vtest.basePort + 3,
@@ -169,7 +167,7 @@ func TestLargeNumberOfKeyspaces(t *testing.T) {
169167
err = vtest.waitUntilDockerHealthy(15)
170168
require.NoError(t, err)
171169

172-
ctx := context.Background()
170+
ctx := t.Context()
173171
vttestParams := mysql.ConnParams{
174172
Host: "localhost",
175173
Port: vtest.basePort + 3,

go/test/endtoend/encryption/encryptedtransport/encrypted_transport_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestSecureTransport(t *testing.T) {
170170

171171
// 'vtgate client 1' is authorized to access vt_insert_test
172172
setCreds(t, "vtgate-client-1", "vtgate-server")
173-
ctx := context.Background()
173+
ctx := t.Context()
174174
request := getRequest("select * from vt_insert_test")
175175
vc, err := getVitessClient(ctx, grpcAddress)
176176
require.NoError(t, err)

go/test/endtoend/messaging/message_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ create table vitess_message(
6969
`
7070

7171
func TestMessage(t *testing.T) {
72-
ctx := context.Background()
72+
ctx := t.Context()
7373

7474
vtParams := mysql.ConnParams{
7575
Host: "localhost",
@@ -207,7 +207,7 @@ create table vitess_message3(
207207
`
208208

209209
func TestThreeColMessage(t *testing.T) {
210-
ctx := context.Background()
210+
ctx := t.Context()
211211

212212
vtParams := mysql.ConnParams{
213213
Host: "localhost",
@@ -300,7 +300,7 @@ var createSpecificStreamingColsMessage = `create table vitess_message4(
300300
) comment 'vitess_message,vt_message_cols=id|msg1,vt_ack_wait=1,vt_purge_after=3,vt_batch_size=2,vt_cache_size=10,vt_poller_interval=1'`
301301

302302
func TestSpecificStreamingColsMessage(t *testing.T) {
303-
ctx := context.Background()
303+
ctx := t.Context()
304304

305305
vtParams := mysql.ConnParams{
306306
Host: "localhost",
@@ -378,7 +378,7 @@ func TestUnsharded(t *testing.T) {
378378
func TestReparenting(t *testing.T) {
379379
name := "sharded_message"
380380

381-
ctx := context.Background()
381+
ctx := t.Context()
382382
// start grpc connection with vtgate and validate client
383383
// connection counts in tablets
384384
stream, err := VtgateGrpcConn(ctx, clusterInstance)
@@ -445,7 +445,7 @@ func TestConnection(t *testing.T) {
445445
assertClientCount(t, 0, shard0Primary)
446446
assertClientCount(t, 0, shard1Primary)
447447

448-
ctx := context.Background()
448+
ctx := t.Context()
449449
// first connection with vtgate
450450
stream, err := VtgateGrpcConn(ctx, clusterInstance)
451451
require.Nil(t, err)
@@ -492,7 +492,7 @@ func TestConnection(t *testing.T) {
492492
}
493493

494494
func testMessaging(t *testing.T, name, ks string) {
495-
ctx := context.Background()
495+
ctx := t.Context()
496496
stream, err := VtgateGrpcConn(ctx, clusterInstance)
497497
require.Nil(t, err)
498498
defer stream.Close()

go/test/endtoend/mysqlserver/mysql_server_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ R442
1818
package mysqlserver
1919

2020
import (
21-
"context"
2221
"database/sql"
2322
"fmt"
2423
"io"
@@ -41,7 +40,7 @@ import (
4140

4241
// TestMultiStmt checks that multiStatements=True and multiStatements=False work properly.
4342
func TestMultiStatement(t *testing.T) {
44-
ctx := context.Background()
43+
ctx := t.Context()
4544

4645
// connect database with multiStatements=True
4746
db := connectDB(t, vtParams, "multiStatements=True", "timeout=90s", "collation=utf8mb4_unicode_ci")
@@ -68,7 +67,7 @@ func TestMultiStatement(t *testing.T) {
6867

6968
// TestLargeComment add large comment in insert stmt and validate the insert process.
7069
func TestLargeComment(t *testing.T) {
71-
ctx := context.Background()
70+
ctx := t.Context()
7271

7372
conn, err := mysql.Connect(ctx, &vtParams)
7473
require.Nilf(t, err, "unable to connect mysql: %v", err)
@@ -86,7 +85,7 @@ func TestLargeComment(t *testing.T) {
8685

8786
// TestInsertLargerThenGrpcLimit insert blob larger then grpc limit and verify the error.
8887
func TestInsertLargerThenGrpcLimit(t *testing.T) {
89-
ctx := context.Background()
88+
ctx := t.Context()
9089

9190
conn, err := mysql.Connect(ctx, &vtParams)
9291
require.Nilf(t, err, "unable to connect mysql: %v", err)
@@ -104,7 +103,7 @@ func TestInsertLargerThenGrpcLimit(t *testing.T) {
104103

105104
// TestTimeout executes sleep(5) with query_timeout of 1 second, and verifies the error.
106105
func TestTimeout(t *testing.T) {
107-
ctx := context.Background()
106+
ctx := t.Context()
108107

109108
conn, err := mysql.Connect(ctx, &vtParams)
110109
require.Nilf(t, err, "unable to connect mysql: %v", err)
@@ -119,7 +118,7 @@ func TestTimeout(t *testing.T) {
119118

120119
// TestInvalidField tries to fetch invalid column and verifies the error.
121120
func TestInvalidField(t *testing.T) {
122-
ctx := context.Background()
121+
ctx := t.Context()
123122

124123
conn, err := mysql.Connect(ctx, &vtParams)
125124
require.Nilf(t, err, "unable to connect mysql: %v", err)
@@ -134,7 +133,7 @@ func TestInvalidField(t *testing.T) {
134133

135134
// TestWarnings validates the behaviour of SHOW WARNINGS.
136135
func TestWarnings(t *testing.T) {
137-
ctx := context.Background()
136+
ctx := t.Context()
138137

139138
conn, err := mysql.Connect(ctx, &vtParams)
140139
require.NoError(t, err)
@@ -175,7 +174,7 @@ func TestWarnings(t *testing.T) {
175174
// TestSelectWithUnauthorizedUser verifies that an unauthorized user
176175
// is not able to read from the table.
177176
func TestSelectWithUnauthorizedUser(t *testing.T) {
178-
ctx := context.Background()
177+
ctx := t.Context()
179178

180179
tmpVtParam := vtParams
181180
tmpVtParam.Uname = "testuser2"

go/test/endtoend/onlineddl/flow/onlineddl_flow_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestMain(m *testing.M) {
196196
}
197197

198198
func TestOnlineDDLFlow(t *testing.T) {
199-
ctx := context.Background()
199+
ctx := t.Context()
200200

201201
require.NotNil(t, clusterInstance)
202202
require.NotNil(t, primaryTablet)
@@ -584,7 +584,7 @@ func initTable(t *testing.T) {
584584
log.Infof("initTable begin")
585585
defer log.Infof("initTable complete")
586586

587-
ctx := context.Background()
587+
ctx := t.Context()
588588
conn, err := mysql.Connect(ctx, &vtParams)
589589
require.Nil(t, err)
590590
defer conn.Close()

go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ func initTable(t *testing.T) {
14201420
log.Infof("initTable begin")
14211421
defer log.Infof("initTable complete")
14221422

1423-
ctx := context.Background()
1423+
ctx := t.Context()
14241424
conn, err := mysql.Connect(ctx, &vtParams)
14251425
require.Nil(t, err)
14261426
defer conn.Close()
@@ -1446,7 +1446,7 @@ func testSelectTableMetrics(t *testing.T) {
14461446

14471447
log.Infof("%s", writeMetrics.String())
14481448

1449-
ctx := context.Background()
1449+
ctx := t.Context()
14501450
conn, err := mysql.Connect(ctx, &vtParams)
14511451
require.NoError(t, err)
14521452
defer conn.Close()

go/test/endtoend/onlineddl/scheduler/onlineddl_scheduler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,7 @@ func testDeclarative(t *testing.T) {
23442344
log.Infof("initTable begin")
23452345
defer log.Infof("initTable complete")
23462346

2347-
ctx := context.Background()
2347+
ctx := t.Context()
23482348
conn, err := mysql.Connect(ctx, &vtParams)
23492349
require.Nil(t, err)
23502350
defer conn.Close()
@@ -2370,7 +2370,7 @@ func testDeclarative(t *testing.T) {
23702370

23712371
log.Infof("%s", writeMetrics.String())
23722372

2373-
ctx := context.Background()
2373+
ctx := t.Context()
23742374
conn, err := mysql.Connect(ctx, &vtParams)
23752375
require.Nil(t, err)
23762376
defer conn.Close()

0 commit comments

Comments
 (0)