Skip to content

Commit

Permalink
Use switch for matching operations
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
  • Loading branch information
serathius committed Nov 16, 2024
1 parent c51e18d commit 4a1855e
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions tests/robustness/validate/patch_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,32 @@ func patchOperations(operations []porcupine.Operation, watchEvents map[model.Eve
var resourceVersion int64
var persisted bool
for _, etcdOp := range append(request.Txn.OperationsOnSuccess, request.Txn.OperationsOnFailure...) {
if etcdOp.Type != model.PutOperation {
continue
}
event, ok := watchEvents[model.Event{
Type: etcdOp.Type,
Key: etcdOp.Put.Key,
Value: etcdOp.Put.Value,
}]
if ok {
eventTime := event.Time.Nanoseconds()
// Set revision and time based on watchEvent.
if eventTime < op.Return {
op.Return = eventTime
switch etcdOp.Type {
case model.PutOperation:
event, ok := watchEvents[model.Event{
Type: etcdOp.Type,
Key: etcdOp.Put.Key,
Value: etcdOp.Put.Value,
}]
if ok {
eventTime := event.Time.Nanoseconds()
// Set revision and time based on watchEvent.
if eventTime < op.Return {
op.Return = eventTime
}
resourceVersion = event.Revision
}
resourceVersion = event.Revision
}
if returnTime, found := persistedOperations[etcdOp]; found {
persisted = true
// Set return time based on persisted return time.
if returnTime < op.Return {
op.Return = returnTime
if returnTime, found := persistedOperations[etcdOp]; found {
persisted = true
// Set return time based on persisted return time.
if returnTime < op.Return {
op.Return = returnTime
}
}
case model.DeleteOperation:
case model.RangeOperation:
default:
panic(fmt.Sprintf("unknown operation type %q", etcdOp.Type))
}
}
if isUniqueTxn(request.Txn) {
Expand Down

0 comments on commit 4a1855e

Please sign in to comment.