Skip to content

Commit 660229b

Browse files
author
Chun-Hung Tseng
committed
Patch the return time with MaxInt64 in robustness test
Reference: - #19579 Signed-off-by: Chun-Hung Tseng <[email protected]>
1 parent 53b88df commit 660229b

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

tests/robustness/model/history.go

+2-30
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ func (h *AppendableHistory) appendFailed(request EtcdRequest, start, end time.Du
290290
}
291291
isRead := request.IsRead()
292292
if !isRead {
293-
// Failed writes can still be persisted, setting -1 for now as don't know when request has took effect.
294-
op.Return = -1
295293
// Operations of single client needs to be sequential.
296294
// As we don't know return time of failed operations, all new writes need to be done with new stream id.
297295
h.streamID = h.idProvider.NewStreamID()
@@ -300,7 +298,7 @@ func (h *AppendableHistory) appendFailed(request EtcdRequest, start, end time.Du
300298
}
301299

302300
func (h *AppendableHistory) append(op porcupine.Operation) {
303-
if op.Return != -1 && op.Call >= op.Return {
301+
if op.Call >= op.Return {
304302
panic(fmt.Sprintf("Invalid operation, call(%d) >= return(%d)", op.Call, op.Return))
305303
}
306304
if len(h.operations) > 0 {
@@ -488,36 +486,10 @@ func (h History) Len() int {
488486

489487
func (h History) Operations() []porcupine.Operation {
490488
operations := make([]porcupine.Operation, 0, len(h.operations))
491-
maxTime := h.lastObservedTime()
492-
for _, op := range h.operations {
493-
// Failed requests don't have a known return time.
494-
if op.Return == -1 {
495-
// Simulate Infinity by using last observed time.
496-
op.Return = maxTime + time.Second.Nanoseconds()
497-
}
498-
operations = append(operations, op)
499-
}
489+
operations = append(operations, h.operations...)
500490
return operations
501491
}
502492

503-
func (h History) lastObservedTime() int64 {
504-
var maxTime int64
505-
for _, op := range h.operations {
506-
if op.Return == -1 {
507-
// Collect call time from failed operations
508-
if op.Call > maxTime {
509-
maxTime = op.Call
510-
}
511-
} else {
512-
// Collect return time from successful operations
513-
if op.Return > maxTime {
514-
maxTime = op.Return
515-
}
516-
}
517-
}
518-
return maxTime
519-
}
520-
521493
func (h History) MaxRevision() int64 {
522494
var maxRevision int64
523495
for _, op := range h.operations {

tests/robustness/validate/patch_history.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package validate
1616

1717
import (
1818
"fmt"
19+
"math"
1920

2021
"github.com/anishathalye/porcupine"
2122

@@ -29,7 +30,9 @@ func patchLinearizableOperations(reports []report.ClientReport, persistedRequest
2930
persistedPutCount := countPersistedPuts(persistedRequests)
3031
clientPutCount := countClientPuts(reports)
3132
putReturnTime := uniquePutReturnTime(allOperations, reports, persistedRequests, clientPutCount)
32-
return patchOperations(allOperations, putRevision, putReturnTime, clientPutCount, persistedPutCount)
33+
patchedOperations := patchOperations(allOperations, putRevision, putReturnTime, clientPutCount, persistedPutCount)
34+
patchFailedOperations(&patchedOperations)
35+
return patchedOperations
3336
}
3437

3538
func relevantOperations(reports []report.ClientReport) []porcupine.Operation {
@@ -239,6 +242,17 @@ func uniquePutReturnTime(allOperations []porcupine.Operation, reports []report.C
239242
return earliestReturnTime
240243
}
241244

245+
// Failed writes can still be persisted, but we don't know when request has took effect, so we override it with MaxInt64
246+
func patchFailedOperations(operations *[]porcupine.Operation) {
247+
for opIdx := range *operations {
248+
request := (*operations)[opIdx].Input.(model.EtcdRequest)
249+
resp := (*operations)[opIdx].Output.(model.MaybeEtcdResponse)
250+
if resp.Error != "" && !request.IsRead() {
251+
(*operations)[opIdx].Return = math.MaxInt64
252+
}
253+
}
254+
}
255+
242256
func countClientPuts(reports []report.ClientReport) map[keyValue]int64 {
243257
counter := map[keyValue]int64{}
244258
for _, client := range reports {

0 commit comments

Comments
 (0)