tests/robustness: Refactor patch operation functions
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
@ -16,12 +16,38 @@ package validate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/anishathalye/porcupine"
|
"github.com/anishathalye/porcupine"
|
||||||
|
|
||||||
"go.etcd.io/etcd/tests/v3/robustness/model"
|
"go.etcd.io/etcd/tests/v3/robustness/model"
|
||||||
"go.etcd.io/etcd/tests/v3/robustness/traffic"
|
"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 {
|
func patchOperationsWithWatchEvents(operations []porcupine.Operation, watchEvents map[model.Event]traffic.TimedWatchEvent) []porcupine.Operation {
|
||||||
|
|
||||||
newOperations := make([]porcupine.Operation, 0, len(operations))
|
newOperations := make([]porcupine.Operation, 0, len(operations))
|
||||||
lastObservedOperation := lastOperationObservedInWatch(operations, watchEvents)
|
lastObservedOperation := lastOperationObservedInWatch(operations, watchEvents)
|
||||||
|
|
||||||
|
@ -17,42 +17,18 @@ package validate
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anishathalye/porcupine"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"go.etcd.io/etcd/tests/v3/robustness/model"
|
|
||||||
"go.etcd.io/etcd/tests/v3/robustness/traffic"
|
"go.etcd.io/etcd/tests/v3/robustness/traffic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValidateAndReturnVisualize returns visualize as porcupine.linearizationInfo used to generate visualization is private.
|
// 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) {
|
func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, reports []traffic.ClientReport) (visualize func(basepath string) error) {
|
||||||
eventHistory := validateWatch(t, cfg, reports)
|
eventHistory := validateWatch(t, cfg, reports)
|
||||||
allOperations := operations(reports)
|
patchedOperations := patchedOperationHistory(reports)
|
||||||
watchEvents := uniqueWatchEvents(reports)
|
|
||||||
patchedOperations := patchOperationsWithWatchEvents(allOperations, watchEvents)
|
|
||||||
return validateOperationsAndVisualize(t, lg, patchedOperations, eventHistory)
|
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 {
|
type Config struct {
|
||||||
ExpectRevisionUnique bool
|
ExpectRevisionUnique bool
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user