Skip to content
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

Use for:range in go test files #15727

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func LaunchCluster(setupType int, streamMode string, stripes int, cDetails *Comp
shard.Vttablets = append(shard.Vttablets, tablet)
return nil
}
for i := 0; i < 4; i++ {
for i := range 4 {
tabletType := tabletTypes[i]
if err := createTablet(tabletType); err != nil {
return 1, err
Expand Down Expand Up @@ -833,7 +833,7 @@ func terminatedRestore(t *testing.T) {
func checkTabletType(t *testing.T, alias string, tabletType topodata.TabletType) {
t.Helper()
// for loop for 15 seconds to check if tablet type is correct
for i := 0; i < 15; i++ {
for range 15 {
output, err := localCluster.VtctldClientProcess.ExecuteCommandWithOutput("GetTablet", alias)
require.Nil(t, err)
var tabletPB topodata.Tablet
Expand Down Expand Up @@ -1169,7 +1169,7 @@ func ReadRowsFromReplica(t *testing.T, replicaIndex int) (msgs []string) {
func FlushBinaryLogsOnReplica(t *testing.T, replicaIndex int, count int) {
replica := getReplica(t, replicaIndex)
query := "flush binary logs"
for i := 0; i < count; i++ {
for range count {
_, err := replica.VttabletProcess.QueryTablet(query, keyspaceName, true)
require.NoError(t, err)
}
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (cluster *LocalProcessCluster) startKeyspace(keyspace Keyspace, shardNames
}
log.Infof("Starting shard: %v", shardName)
var mysqlctlProcessList []*exec.Cmd
for i := 0; i < totalTabletsRequired; i++ {
for i := range totalTabletsRequired {
// instantiate vttablet object with reserved ports
tabletUID := cluster.GetAndReserveTabletUID()
tablet := &Vttablet{
Expand Down Expand Up @@ -534,7 +534,7 @@ func (cluster *LocalProcessCluster) StartKeyspaceLegacy(keyspace Keyspace, shard
}
log.Infof("Starting shard: %v", shardName)
mysqlctlProcessList = []*exec.Cmd{}
for i := 0; i < totalTabletsRequired; i++ {
for i := range totalTabletsRequired {
// instantiate vttablet object with reserved ports
tabletUID := cluster.GetAndReserveTabletUID()
tablet := &Vttablet{
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/cluster/vttablet_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func executeQuery(dbConn *mysql.Conn, query string) (*sqltypes.Result, error) {
)
retries := 10
retryDelay := 1 * time.Second
for i := 0; i < retries; i++ {
for i := range retries {
if i > 0 {
// We only audit from 2nd attempt and onwards, otherwise this is just too verbose.
log.Infof("Executing query %s (attempt %d of %d)", query, (i + 1), retries)
Expand All @@ -551,7 +551,7 @@ func executeQuery(dbConn *mysql.Conn, query string) (*sqltypes.Result, error) {
func executeMultiQuery(dbConn *mysql.Conn, query string) (err error) {
retries := 10
retryDelay := 1 * time.Second
for i := 0; i < retries; i++ {
for i := range retries {
if i > 0 {
// We only audit from 2nd attempt and onwards, otherwise this is just too verbose.
log.Infof("Executing query %s (attempt %d of %d)", query, (i + 1), retries)
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/docker/vttestserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestLargeNumberOfKeyspaces(t *testing.T) {
t.Run(image, func(t *testing.T) {
var keyspaces []string
var numShards []int
for i := 0; i < 100; i++ {
for i := range 100 {
keyspaces = append(keyspaces, fmt.Sprintf("unsharded_ks%d", i))
numShards = append(numShards, 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func initializeCluster(t *testing.T) (int, error) {
shard := &cluster.Shard{
Name: shardName,
}
for i := 0; i < 2; i++ {
for range 2 {
// instantiate vttablet object with reserved ports
tabletUID := clusterInstance.GetAndReserveTabletUID()
tablet := clusterInstance.NewVttabletInstance("replica", tabletUID, cell)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func clusterSetUp(t *testing.T) (int, error) {
shard := &cluster.Shard{
Name: shardName,
}
for i := 0; i < 2; i++ {
for range 2 {
// instantiate vttablet object with reserved ports
tablet := clusterInstance.NewVttabletInstance("replica", 0, cell)

Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/mysqlctl/mysqlctl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func initCluster(shardNames []string, totalTabletsRequired int) {
Name: shardName,
}
var mysqlCtlProcessList []*exec.Cmd
for i := 0; i < totalTabletsRequired; i++ {
for i := range totalTabletsRequired {
// instantiate vttablet object with reserved ports
tabletUID := clusterInstance.GetAndReserveTabletUID()
tablet := &cluster.Vttablet{
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/mysqlctld/mysqlctld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func initCluster(shardNames []string, totalTabletsRequired int) error {
shard := &cluster.Shard{
Name: shardName,
}
for i := 0; i < totalTabletsRequired; i++ {
for i := range totalTabletsRequired {
// instantiate vttablet object with reserved ports
tabletUID := clusterInstance.GetAndReserveTabletUID()
tablet := &cluster.Vttablet{
Expand Down
10 changes: 5 additions & 5 deletions go/test/endtoend/onlineddl/revert/onlineddl_revert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ func testRevert(t *testing.T) {
// If they fail, it has nothing to do with revert.
// We run these tests because we expect their functionality to work in the next step.
var alterHints []string
for i := 0; i < 2; i++ {
for i := range 2 {
testName := fmt.Sprintf("online ALTER TABLE %d", i)
hint := fmt.Sprintf("hint-alter-%d", i)
alterHints = append(alterHints, hint)
Expand Down Expand Up @@ -1388,7 +1388,7 @@ func runMultipleConnections(ctx context.Context, t *testing.T) {
require.True(t, checkTable(t, tableName, true))
var done int64
var wg sync.WaitGroup
for i := 0; i < maxConcurrency; i++ {
for range maxConcurrency {
wg.Add(1)
go func() {
defer wg.Done()
Expand All @@ -1415,13 +1415,13 @@ func initTable(t *testing.T) {
_, err = conn.ExecuteFetch(truncateStatement, 1000, true)
require.Nil(t, err)

for i := 0; i < maxTableRows/2; i++ {
for range maxTableRows / 2 {
generateInsert(t, conn)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateUpdate(t, conn)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateDelete(t, conn)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1698,13 +1698,13 @@ func testDeclarative(t *testing.T) {
_, err = conn.ExecuteFetch(truncateStatement, 1000, true)
require.Nil(t, err)

for i := 0; i < maxTableRows/2; i++ {
for range maxTableRows / 2 {
generateInsert(t, conn)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateUpdate(t, conn)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateDelete(t, conn)
}
}
Expand Down
9 changes: 4 additions & 5 deletions go/test/endtoend/onlineddl/vrepl/onlineddl_vrepl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func TestSchemaChange(t *testing.T) {
// spawn n migrations; cancel them via cancel-all
var wg sync.WaitGroup
count := 4
for i := 0; i < count; i++ {
for range count {
wg.Add(1)
go func() {
defer wg.Done()
Expand All @@ -487,8 +487,7 @@ func TestSchemaChange(t *testing.T) {

// spawn n migrations; cancel them via cancel-all
var wg sync.WaitGroup
count := 4
for i := 0; i < count; i++ {
for range 4 {
wg.Add(1)
go func() {
defer wg.Done()
Expand Down Expand Up @@ -867,7 +866,7 @@ func insertRow(t *testing.T) {
}

func insertRows(t *testing.T, count int) {
for i := 0; i < count; i++ {
for range count {
insertRow(t)
}
}
Expand Down Expand Up @@ -903,7 +902,7 @@ func testMigrationRowCount(t *testing.T, uuid string) {
func testWithInitialSchema(t *testing.T) {
// Create 4 tables
var sqlQuery = "" //nolint
for i := 0; i < totalTableCount; i++ {
for i := range totalTableCount {
sqlQuery = fmt.Sprintf(createTable, fmt.Sprintf("vt_onlineddl_test_%02d", i))
err := clusterInstance.VtctldClientProcess.ApplySchema(keyspaceName, sqlQuery)
require.Nil(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestSchemaChange(t *testing.T) {
assert.Equal(t, 1, len(clusterInstance.Keyspaces[0].Shards))
testWithInitialSchema(t)
})
for i := 0; i < countIterations; i++ {
for i := range countIterations {
// This first tests the general functionality of initializing the table with data,
// no concurrency involved. Just counting.
testName := fmt.Sprintf("init table %d/%d", (i + 1), countIterations)
Expand All @@ -252,7 +252,7 @@ func TestSchemaChange(t *testing.T) {
testSelectTableMetrics(t)
})
}
for i := 0; i < countIterations; i++ {
for i := range countIterations {
// This tests running a workload on the table, then comparing expected metrics with
// actual table metrics. All this without any ALTER TABLE: this is to validate
// that our testing/metrics logic is sound in the first place.
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestSchemaChange(t *testing.T) {
testSelectTableMetrics(t)
})

for i := 0; i < countIterations; i++ {
for i := range countIterations {
// Finally, this is the real test:
// We populate a table, and begin a concurrent workload (this is the "mini stress")
// We then ALTER TABLE via vreplication.
Expand Down Expand Up @@ -546,7 +546,7 @@ func runMultipleConnections(ctx context.Context, t *testing.T) {

log.Infof("Running multiple connections: maxConcurrency=%v, sleep interval=%v", maxConcurrency, sleepInterval)
var wg sync.WaitGroup
for i := 0; i < maxConcurrency; i++ {
for range maxConcurrency {
wg.Add(1)
go func() {
defer wg.Done()
Expand Down Expand Up @@ -579,13 +579,13 @@ func initTable(t *testing.T) {
_, err = conn.ExecuteFetch(truncateStatement, 1000, true)
require.Nil(t, err)

for i := 0; i < maxTableRows/2; i++ {
for range maxTableRows / 2 {
generateInsert(t, conn)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateUpdate(t, conn)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateDelete(t, conn)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ func runMultipleConnections(ctx context.Context, t *testing.T, autoIncInsert boo
log.Infof("Running multiple connections")
var done int64
var wg sync.WaitGroup
for i := 0; i < maxConcurrency; i++ {
for range maxConcurrency {
wg.Add(1)
go func() {
defer wg.Done()
Expand Down Expand Up @@ -766,13 +766,13 @@ func initTable(t *testing.T) {
_, err = conn.ExecuteFetch(truncateStatement, 1000, true)
require.Nil(t, err)

for i := 0; i < maxTableRows/2; i++ {
for range maxTableRows / 2 {
generateInsert(t, conn, false)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateUpdate(t, conn)
}
for i := 0; i < maxTableRows/4; i++ {
for range maxTableRows / 4 {
generateDelete(t, conn)
}
{
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/recovery/unshardedrecovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestMainImpl(m *testing.M) {
}

var mysqlProcs []*exec.Cmd
for i := 0; i < 4; i++ {
for i := range 4 {
tabletType := "replica"
if i == 0 {
tabletType = "primary"
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/reparent/emergencyreparent/ers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func TestERSForInitialization(t *testing.T) {
require.NoError(t, err)
err = clusterInstance.TopoProcess.ManageTopoDir("mkdir", "/vitess/"+"zone1")
require.NoError(t, err)
for i := 0; i < 4; i++ {
for i := range 4 {
tablet := clusterInstance.NewVttabletInstance("replica", 100+i, "zone1")
tablets = append(tablets, tablet)
}
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/reparent/prscomplex/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestAcquireSameConnID(t *testing.T) {
totalErrCount := 0
// run through 100 times to acquire new connection, this might override the original connection id.
var conn2 *mysql.Conn
for i := 0; i < 100; i++ {
for range 100 {
conn2, err = mysql.Connect(ctx, &vtParams)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/sharded/sharded_keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func initCluster(shardNames []string, totalTabletsRequired int) {

var mysqlCtlProcessList []*exec.Cmd

for i := 0; i < totalTabletsRequired; i++ {
for i := range totalTabletsRequired {
// instantiate vttablet object with reserved ports
tabletUID := clusterInstance.GetAndReserveTabletUID()
tablet := &cluster.Vttablet{
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/tabletgateway/vtgate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestStreamingRPCStuck(t *testing.T) {
// We want the table to have enough rows such that a streaming call returns multiple packets.
// Therefore, we insert one row and keep doubling it.
utils.Exec(t, vtConn, "insert into customer(email) values('testemail')")
for i := 0; i < 15; i++ {
for range 15 {
// Double the number of rows in customer table.
utils.Exec(t, vtConn, "insert into customer (email) select email from customer")
}
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/tabletmanager/qps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestQPS(t *testing.T) {
// after that we'll see 0.0 QPS rates again. If this becomes actually
// flaky, we need to read continuously in a separate thread.

for n := 0; n < 15; n++ {
for range 15 {
// Run queries via vtGate so that they are counted.
utils.Exec(t, vtGateConn, "select * from t1")
}
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/tabletmanager/tablegc/tablegc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func populateTable(t *testing.T) {
require.NoError(t, err)
_, err = primaryTablet.VttabletProcess.QueryTablet("insert into t1 (id, value) values (null, md5(rand()))", keyspaceName, true)
require.NoError(t, err)
for i := 0; i < 10; i++ {
for range 10 {
_, err = primaryTablet.VttabletProcess.QueryTablet("insert into t1 (id, value) select null, md5(rand()) from t1", keyspaceName, true)
require.NoError(t, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func TestCustomQuery(t *testing.T) {
sleepDuration := 20 * time.Second
var wg sync.WaitGroup
t.Run("generate running queries", func(t *testing.T) {
for i := 0; i < customThreshold+1; i++ {
for i := range customThreshold + 1 {
// Generate different Sleep() calls, all at minimum sleepDuration.
wg.Add(1)
go func(i int) {
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestVaultAuth(t *testing.T) {
defer vs.stop()

// Wait for Vault server to come up
for i := 0; i < 60; i++ {
for range 60 {
time.Sleep(250 * time.Millisecond)
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", hostname, vs.port1))
if err != nil {
Expand Down Expand Up @@ -164,7 +164,7 @@ func startVaultServer(t *testing.T) *Server {
}

// Setup everything we need in the Vault server
func setupVaultServer(t *testing.T, vs *Server) (string, string) {
func setupVaultServer(_ *testing.T, vs *Server) (string, string) {
// The setup script uses these environment variables
// We also reuse VAULT_ADDR and VAULT_CACERT later on
os.Setenv("VAULT", vs.execPath)
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/versionupgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestDeploySchema(t *testing.T) {
return
}
// Create n tables, populate
for i := 0; i < totalTableCount; i++ {
for i := range totalTableCount {
tableName := fmt.Sprintf("vt_upgrade_test_%02d", i)

{
Expand Down Expand Up @@ -186,7 +186,7 @@ func checkTablesCount(t *testing.T, tablet *cluster.Vttablet, showTableName stri
// TestTablesData checks the data in tables
func TestTablesData(t *testing.T) {
// Create n tables, populate
for i := 0; i < totalTableCount; i++ {
for i := range totalTableCount {
tableName := fmt.Sprintf("vt_upgrade_test_%02d", i)

for i := range clusterInstance.Keyspaces[0].Shards {
Expand Down