Skip to content

Commit

Permalink
tests: Fix history patch window
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
  • Loading branch information
serathius committed Jan 13, 2023
1 parent 6315f1c commit 1257d0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 5 additions & 3 deletions tests/linearizability/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
17 changes: 15 additions & 2 deletions tests/linearizability/linearizability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 1257d0d

Please sign in to comment.