Repository: etcd-io/etcd
File: tests/antithesis/test-template/robustness/traffic/main.go (Go)

Code before:
		"kubernetes",
	}
	traffics = []traffic.Traffic{
		traffic.EtcdPutDeleteLease,
		traffic.KubernetesCreateDelete,
	}
)

func main() {
	local := flag.Bool("local", false, "run tests locally and connect to etcd instances via localhost")
	flag.Parse()

	reportPath, hosts, etcdetcdDataPaths := common.DefaultPaths()
	if *local {
		reportPath, hosts, etcdetcdDataPaths = common.LocalPaths()
	}

	ctx := context.Background()
	baseTime := time.Now()
	duration := time.Duration(robustnessrand.RandRange(5, 15) * int64(time.Second))

	lg, err := zap.NewProduction()
	if err != nil {
		panic(err)
	}
	choice := rand.IntN(2)
	tf := traffics[choice]
	lg.Info("Traffic", zap.String("Type", trafficNames[choice]))
	r := report.TestReport{Logger: lg, ServersDataPath: etcdetcdDataPaths}
	defer func() {
		if err = r.Report(reportPath); err != nil {
			lg.Error("Failed to save traffic generation report", zap.Error(err))
		}
	}()

	lg.Info("Start traffic generation", zap.Duration("duration", duration))
	r.Client, err = runTraffic(ctx, lg, tf, hosts, baseTime, duration)
	if err != nil {
		lg.Error("Failed to generate traffic")
		panic(err)
	}
}

func runTraffic(ctx context.Context, lg *zap.Logger, tf traffic.Traffic, hosts []string, baseTime time.Time, duration time.Duration) ([]report.ClientReport, error) {
	ids := identity.NewIDProvider()
	r, err := traffic.CheckEmptyDatabaseAtStart(ctx, lg, hosts, ids, baseTime)
	if err != nil {
		lg.Fatal("Failed empty database at start check", zap.Error(err))
	}
	trafficReports := []report.ClientReport{r}
	watchReport := []report.ClientReport{}

Review comment (suggestion):
```suggestion
	choice := rand.IntN(len(traffics)
```

Code after:
		"kubernetes",
	}
	traffics = []traffic.Traffic{
		traffic.EtcdPutDeleteLease,
		traffic.Kubernetes,
	}
)

func main() {
	local := flag.Bool("local", false, "run tests locally and connect to etcd instances via localhost")
	flag.Parse()

	reportPath, hosts, etcdetcdDataPaths := common.DefaultPaths()
	if *local {
		reportPath, hosts, etcdetcdDataPaths = common.LocalPaths()
	}

	ctx := context.Background()
	baseTime := time.Now()
	duration := time.Duration(robustnessrand.RandRange(5, 15) * int64(time.Second))

	lg, err := zap.NewProduction()
	if err != nil {
		panic(err)
	}
	choice := rand.IntN(len(traffics))
	tf := traffics[choice]
	lg.Info("Traffic", zap.String("Type", trafficNames[choice]))
	r := report.TestReport{Logger: lg, ServersDataPath: etcdetcdDataPaths}
	defer func() {
		if err = r.Report(reportPath); err != nil {
			lg.Error("Failed to save traffic generation report", zap.Error(err))
		}
	}()

	lg.Info("Start traffic generation", zap.Duration("duration", duration))
	r.Client, err = runTraffic(ctx, lg, tf, hosts, baseTime, duration)
	if err != nil {
		lg.Error("Failed to generate traffic")
		panic(err)
	}
}

func runTraffic(ctx context.Context, lg *zap.Logger, tf traffic.Traffic, hosts []string, baseTime time.Time, duration time.Duration) ([]report.ClientReport, error) {
	ids := identity.NewIDProvider()
	r, err := traffic.CheckEmptyDatabaseAtStart(ctx, lg, hosts, ids, baseTime)
	if err != nil {
		lg.Fatal("Failed empty database at start check", zap.Error(err))
	}
	trafficReports := []report.ClientReport{r}
	watchReport := []report.ClientReport{}