Skip to content

Commit b0731c0

Browse files
committed
validate: Improve linearization request replay
- Add getLinearizedRequests function to preserve error responses during replay - Modify ValidateAndReturnVisualize to use linearized operations - Ensure failed operations are correctly positioned in the replay sequence
1 parent eb7607b commit b0731c0

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

tests/robustness/validate/validate.go

+38-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report
4040
return results
4141
}
4242

43-
// TODO: Use requests from linearization for replay.
44-
replay := model.NewReplay(persistedRequests)
43+
// Use linearization results from operations
44+
linearizedRequests := getLinearizedRequests(linearizableOperations, reports, persistedRequests)
45+
replay := model.NewReplay(linearizedRequests)
4546

4647
err = validateWatch(lg, cfg, reports, replay)
4748
if err != nil {
@@ -54,6 +55,41 @@ func ValidateAndReturnVisualize(t *testing.T, lg *zap.Logger, cfg Config, report
5455
return results
5556
}
5657

58+
// getLinearizedRequests converts linearizable operations to a sequence of requests
59+
// while preserving error responses from the client reports
60+
func getLinearizedRequests(operations []porcupine.Operation, reports []report.ClientReport, persistedRequests []model.EtcdRequest) []model.EtcdRequest {
61+
result := make([]model.EtcdRequest, 0, len(persistedRequests))
62+
63+
// Build map of failed operations from client reports
64+
failedOps := make(map[int]bool)
65+
for _, report := range reports {
66+
for _, op := range report.KeyValue {
67+
response := op.Output.(model.MaybeEtcdResponse)
68+
if response.Error != "" {
69+
failedOps[op.ClientId] = true
70+
}
71+
}
72+
}
73+
74+
// Track processed operations
75+
opIndex := 0
76+
77+
// Build sequence combining linearized operations and error responses
78+
for i := range persistedRequests {
79+
if failedOps[i] {
80+
// Keep failed operations in their original position
81+
result = append(result, persistedRequests[i])
82+
} else if opIndex < len(operations) {
83+
// Use operations order for successful requests
84+
originalIndex := operations[opIndex].Input.(int)
85+
result = append(result, persistedRequests[originalIndex])
86+
opIndex++
87+
}
88+
}
89+
90+
return result
91+
}
92+
5793
type Config struct {
5894
ExpectRevisionUnique bool
5995
}

0 commit comments

Comments
 (0)