diff --git a/tests/linearizability/history.go b/tests/linearizability/history.go index f6167309949..6a3fde13b62 100644 --- a/tests/linearizability/history.go +++ b/tests/linearizability/history.go @@ -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) } diff --git a/tests/linearizability/linearizability_test.go b/tests/linearizability/linearizability_test.go index 23f199bb8c3..bf1e1fef565 100644 --- a/tests/linearizability/linearizability_test.go +++ b/tests/linearizability/linearizability_test.go @@ -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 {