mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: Fix history patch window
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
6315f1cfdc
commit
1257d0d919
@ -284,12 +284,14 @@ func (h history) Operations() []porcupine.Operation {
|
||||
maxTime = op.Return
|
||||
}
|
||||
}
|
||||
// Failed requests don't have a known return time.
|
||||
// We simulate Infinity by using return time of latest successfully request.
|
||||
for _, op := range h.failed {
|
||||
if op.Call > maxTime {
|
||||
continue
|
||||
maxTime = op.Call
|
||||
}
|
||||
}
|
||||
// Failed requests don't have a known return time.
|
||||
// Simulate Infinity by using last observed time.
|
||||
for _, op := range h.failed {
|
||||
op.Return = maxTime + 1
|
||||
operations = append(operations, op)
|
||||
}
|
||||
|
@ -143,11 +143,11 @@ func patchOperationBasedOnWatchEvents(operations []porcupine.Operation, watchEve
|
||||
for _, op := range watchEvents {
|
||||
persisted[op.Op] = op
|
||||
}
|
||||
lastObservedEventTime := watchEvents[len(watchEvents)-1].Time
|
||||
lastObservedOperation := lastOperationObservedInWatch(operations, persisted)
|
||||
|
||||
for _, op := range operations {
|
||||
resp := op.Output.(EtcdResponse)
|
||||
if resp.Err == nil || op.Call > lastObservedEventTime.UnixNano() {
|
||||
if resp.Err == nil || op.Call > lastObservedOperation.Call {
|
||||
// No need to patch successfully requests and cannot patch requests outside observed window.
|
||||
newOperations = append(newOperations, op)
|
||||
continue
|
||||
@ -173,6 +173,19 @@ func patchOperationBasedOnWatchEvents(operations []porcupine.Operation, watchEve
|
||||
return newOperations
|
||||
}
|
||||
|
||||
func lastOperationObservedInWatch(operations []porcupine.Operation, watchEvents map[EtcdOperation]watchEvent) porcupine.Operation {
|
||||
var maxCallTime int64
|
||||
var lastOperation porcupine.Operation
|
||||
for _, op := range operations {
|
||||
event, _ := matchWatchEvent(op, watchEvents)
|
||||
if event != nil && op.Call > maxCallTime {
|
||||
maxCallTime = op.Call
|
||||
lastOperation = op
|
||||
}
|
||||
}
|
||||
return lastOperation
|
||||
}
|
||||
|
||||
func matchWatchEvent(op porcupine.Operation, watchEvents map[EtcdOperation]watchEvent) (event *watchEvent, hasUniqueWriteOperation bool) {
|
||||
request := op.Input.(EtcdRequest)
|
||||
for _, etcdOp := range request.Ops {
|
||||
|
Loading…
x
Reference in New Issue
Block a user