diff --git a/tests/robustness/validate/patch_history.go b/tests/robustness/validate/patch_history.go index aebb0ebf220..259240feebb 100644 --- a/tests/robustness/validate/patch_history.go +++ b/tests/robustness/validate/patch_history.go @@ -16,12 +16,38 @@ package validate import ( "github.com/anishathalye/porcupine" - "go.etcd.io/etcd/tests/v3/robustness/model" "go.etcd.io/etcd/tests/v3/robustness/traffic" ) +func patchedOperationHistory(reports []traffic.ClientReport) []porcupine.Operation { + allOperations := operations(reports) + uniqueEvents := uniqueWatchEvents(reports) + return patchOperationsWithWatchEvents(allOperations, uniqueEvents) +} + +func operations(reports []traffic.ClientReport) []porcupine.Operation { + var ops []porcupine.Operation + for _, r := range reports { + ops = append(ops, r.OperationHistory.Operations()...) + } + return ops +} + +func uniqueWatchEvents(reports []traffic.ClientReport) map[model.Event]traffic.TimedWatchEvent { + persisted := map[model.Event]traffic.TimedWatchEvent{} + for _, r := range reports { + for _, resp := range r.Watch { + for _, event := range resp.Events { + persisted[event.Event] = traffic.TimedWatchEvent{Time: resp.Time, WatchEvent: event} + } + } + } + return persisted +} + func patchOperationsWithWatchEvents(operations []porcupine.Operation, watchEvents map[model.Event]traffic.TimedWatchEvent) []porcupine.Operation { + newOperations := make([]porcupine.Operation, 0, len(operations)) lastObservedOperation := lastOperationObservedInWatch(operations, watchEvents) diff --git a/tests/robustness/validate/validate.go b/tests/robustness/validate/validate.go index 612e5a116c5..0364fd340ac 100644 --- a/tests/robustness/validate/validate.go +++ b/tests/robustness/validate/validate.go @@ -17,42 +17,18 @@ package validate import ( "testing" - "github.com/anishathalye/porcupine" "go.uber.org/zap" - "go.etcd.io/etcd/tests/v3/robustness/model" "go.etcd.io/etcd/tests/v3/robustness/traffic" ) // ValidateAndReturnVisualize returns visualize as porcupine.linearizationInfo used to generate visualization is private. func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, reports []traffic.ClientReport) (visualize func(basepath string) error) { eventHistory := validateWatch(t, cfg, reports) - allOperations := operations(reports) - watchEvents := uniqueWatchEvents(reports) - patchedOperations := patchOperationsWithWatchEvents(allOperations, watchEvents) + patchedOperations := patchedOperationHistory(reports) return validateOperationsAndVisualize(t, lg, patchedOperations, eventHistory) } -func operations(reports []traffic.ClientReport) []porcupine.Operation { - var ops []porcupine.Operation - for _, r := range reports { - ops = append(ops, r.OperationHistory.Operations()...) - } - return ops -} - -func uniqueWatchEvents(reports []traffic.ClientReport) map[model.Event]traffic.TimedWatchEvent { - persisted := map[model.Event]traffic.TimedWatchEvent{} - for _, r := range reports { - for _, resp := range r.Watch { - for _, event := range resp.Events { - persisted[event.Event] = traffic.TimedWatchEvent{Time: resp.Time, WatchEvent: event} - } - } - } - return persisted -} - type Config struct { ExpectRevisionUnique bool }