Skip to content

Commit

Permalink
tests/robustness: Refactor patch operation functions
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <[email protected]>
  • Loading branch information
serathius committed Jun 24, 2023
1 parent 0e82329 commit 0ae8f26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
28 changes: 27 additions & 1 deletion tests/robustness/validate/patch_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 1 addition & 25 deletions tests/robustness/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 0ae8f26

Please sign in to comment.