mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests/robustness: Refactor patch operation functions
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
0e8232950a
commit
0ae8f26f06
@ -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)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user