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 (
|
||||
"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)
|
||||
|
||||
|
Reference in New Issue
Block a user