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

validate: Refactor linearization handling and visualization in operations.go #19094

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
39 changes: 30 additions & 9 deletions tests/robustness/validate/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,38 @@ var (
errFutureRevRespRequested = errors.New("request about a future rev with response")
)

func validateLinearizableOperationsAndVisualize(lg *zap.Logger, operations []porcupine.Operation, timeout time.Duration) (result porcupine.CheckResult, visualize func(basepath string) error) {
type Results struct {
Info porcupine.LinearizationInfo
Model porcupine.Model
Lg *zap.Logger // Include logger in the Results struct
serathius marked this conversation as resolved.
Show resolved Hide resolved
}

// Change the Visualize method to match the signature func(path string) error
serathius marked this conversation as resolved.
Show resolved Hide resolved
func (r Results) Visualize(path string) error {
// Directly use the logger from the Results struct
r.Lg.Info("Saving visualization", zap.String("path", path))
err := porcupine.VisualizePath(r.Model, r.Info, path)
if err != nil {
return fmt.Errorf("failed to visualize, err: %w", err)
}
return nil
}

func validateLinearizableOperationsAndVisualize(
lg *zap.Logger,
operations []porcupine.Operation,
timeout time.Duration,
) (result porcupine.CheckResult, results Results) {
lg.Info("Validating linearizable operations", zap.Duration("timeout", timeout))
start := time.Now()
result, info := porcupine.CheckOperationsVerbose(model.NonDeterministicModel, operations, timeout)

results = Results{
Info: info,
Model: model.NonDeterministicModel,
Lg: lg,
}

switch result {
case porcupine.Illegal:
lg.Error("Linearization failed", zap.Duration("duration", time.Since(start)))
Expand All @@ -46,14 +74,7 @@ func validateLinearizableOperationsAndVisualize(lg *zap.Logger, operations []por
default:
panic(fmt.Sprintf("Unknown Linearization result %s", result))
}
return result, func(path string) error {
lg.Info("Saving visualization", zap.String("path", path))
err := porcupine.VisualizePath(model.NonDeterministicModel, info, path)
if err != nil {
return fmt.Errorf("failed to visualize, err: %w", err)
}
return nil
}
return result, results
}

func validateSerializableOperations(lg *zap.Logger, operations []porcupine.Operation, replay *model.EtcdReplay) (lastErr error) {
Expand Down
7 changes: 4 additions & 3 deletions tests/robustness/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report
linearizableOperations := patchLinearizableOperations(reports, persistedRequests)
serializableOperations := filterSerializableOperations(reports)

linearizable, visualize := validateLinearizableOperationsAndVisualize(lg, linearizableOperations, timeout)
linearizable, results := validateLinearizableOperationsAndVisualize(lg, linearizableOperations, timeout)
if linearizable != porcupine.Ok {
t.Error("Failed linearization, skipping further validation")
return visualize
return results.Visualize
serathius marked this conversation as resolved.
Show resolved Hide resolved
}

// TODO: Use requests from linearization for replay.
replay := model.NewReplay(persistedRequests)

Expand All @@ -51,7 +52,7 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report
if err != nil {
t.Errorf("Failed validating serializable operations, err: %s", err)
}
return visualize
return results.Visualize
}

type Config struct {
Expand Down
Loading