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

Code before:

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

	reportPath, _, dirs := common.DefaultPaths()
	if *local {
		reportPath, _, dirs = common.LocalPaths()
	}

	lg, err := zap.NewProduction()
	if err != nil {
		panic(err)
	}
	r := report.TestReport{Logger: lg, ServersDataPath: dirs}
	r.Client, err = report.LoadClientReports(reportPath)
	assert.Always(err == nil, "Loaded client reports", map[string]any{"error": err})
	defer func() {
		if err := r.Report(reportPath); err != nil {
			lg.Error("Failed to save validation report", zap.Error(err))
		}
	}()
	testValidate(lg, r)
}

func testValidate(lg *zap.Logger, r report.TestReport) {
	persistedRequests, err := report.PersistedRequests(lg, slices.Collect(maps.Values(r.ServersDataPath)))
	assert.Always(err == nil, "Loaded persisted requests", map[string]any{"error": err})

	validateConfig := validate.Config{ExpectRevisionUnique: traffic.EtcdAntithesis.ExpectUniqueRevision()}
	result := validate.ValidateAndReturnVisualize(lg, validateConfig, r.Client, persistedRequests, 5*time.Minute)
	assert.Always(result.Assumptions == nil, "Validation assumptions fulfilled", map[string]any{"error": result.Assumptions})
	if result.Linearization.Linearizable == porcupine.Unknown {
		assert.Unreachable("Linearization timeout", nil)
	} else {
		assert.Always(result.Linearization.Linearizable == porcupine.Ok, "Linearization validation passes", nil)
	}
	r.Visualize = result.Linearization.Visualize
	assert.Always(result.WatchError == nil, "Watch validation passes", map[string]any{"error": result.WatchError})
	assert.Always(result.SerializableError == nil, "Serializable validation passes", map[string]any{"error": result.SerializableError})
	lg.Info("Completed robustness validation")
}


Review comment (suggestion):
```suggestion
func validate(lg *zap.Logger, r report.TestReport) {
```

Code after:
)

const (
	reportFileName = "history.html"
)

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

	reportPath, _, dirs := common.DefaultPaths()
	if *local {
		reportPath, _, dirs = common.LocalPaths()
	}

	lg, err := zap.NewProduction()
	if err != nil {
		panic(err)
	}
	reports, err := report.LoadClientReports(reportPath)
	assert.Always(err == nil, "Loaded client reports", map[string]any{"error": err})
	result := validateReports(lg, dirs, reports)
	if err := result.Linearization.Visualize(lg, filepath.Join(reportPath, reportFileName)); err != nil {
		panic(err)
	}
}

func validateReports(lg *zap.Logger, serversDataPath map[string]string, reports []report.ClientReport) validate.Result {
	persistedRequests, err := report.PersistedRequests(lg, slices.Collect(maps.Values(serversDataPath)))
	assert.Always(err == nil, "Loaded persisted requests", map[string]any{"error": err})

	validateConfig := validate.Config{ExpectRevisionUnique: traffic.EtcdAntithesis.ExpectUniqueRevision()}
	result := validate.ValidateAndReturnVisualize(lg, validateConfig, reports, persistedRequests, 5*time.Minute)
	assert.Always(result.Assumptions == nil, "Validation assumptions fulfilled", map[string]any{"error": result.Assumptions})
	if result.Linearization.Linearizable == porcupine.Unknown {
		assert.Unreachable("Linearization timeout", nil)
	} else {
		assert.Always(result.Linearization.Linearizable == porcupine.Ok, "Linearization validation passes", nil)
	}
	assert.Always(result.WatchError == nil, "Watch validation passes", map[string]any{"error": result.WatchError})
	assert.Always(result.SerializableError == nil, "Serializable validation passes", map[string]any{"error": result.SerializableError})
	lg.Info("Completed robustness validation")
	return result
}