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

Code before:
	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{}
	maxRevisionChan := make(chan int64, 1)
	watchConfig := client.WatchConfig{

Review comment (suggestion):
Remove reference to traffic.EtcdPutDeleteLease in https://github.com/etcd-io/etcd/blob/1e357cfc90b7318e7be543c63ae36e44cb63a6e3/tests/antithesis/test-template/robustness/finally/main.go#L64

We can just set `ExpectRevisionUnique` to `false`.

Code after:
	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{}
	maxRevisionChan := make(chan int64, 1)
	watchConfig := client.WatchConfig{