tests/robustness: Rename operations const to separate from RequestType

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
dependabot/go_modules/github.com/prometheus/procfs-0.11.0
Marek Siarkowicz 2023-06-14 13:24:06 +02:00
parent da49157b20
commit 974655e02c
8 changed files with 44 additions and 44 deletions

View File

@ -100,7 +100,7 @@ func describeTxnResponse(request *TxnRequest, response *TxnResponse) string {
func describeEtcdOperation(op EtcdOperation) string {
switch op.Type {
case Range:
case RangeOperation:
if op.WithPrefix {
if op.Limit != 0 {
return fmt.Sprintf("range(%q, limit=%d)", op.Key, op.Limit)
@ -108,12 +108,12 @@ func describeEtcdOperation(op EtcdOperation) string {
return fmt.Sprintf("range(%q)", op.Key)
}
return fmt.Sprintf("get(%q)", op.Key)
case Put:
case PutOperation:
if op.LeaseID != 0 {
return fmt.Sprintf("put(%q, %s, %d)", op.Key, describeValueOrHash(op.Value), op.LeaseID)
}
return fmt.Sprintf("put(%q, %s)", op.Key, describeValueOrHash(op.Value))
case Delete:
case DeleteOperation:
return fmt.Sprintf("delete(%q)", op.Key)
default:
return fmt.Sprintf("<! unknown op: %q !>", op.Type)
@ -122,7 +122,7 @@ func describeEtcdOperation(op EtcdOperation) string {
func describeEtcdOperationResponse(req EtcdOperation, resp EtcdOperationResult) string {
switch req.Type {
case Range:
case RangeOperation:
if req.WithPrefix {
kvs := make([]string, len(resp.KVs))
for i, kv := range resp.KVs {
@ -136,9 +136,9 @@ func describeEtcdOperationResponse(req EtcdOperation, resp EtcdOperationResult)
return describeValueOrHash(resp.KVs[0].Value)
}
}
case Put:
case PutOperation:
return fmt.Sprintf("ok")
case Delete:
case DeleteOperation:
return fmt.Sprintf("deleted: %d", resp.Deleted)
default:
return fmt.Sprintf("<! unknown op: %q !>", req.Type)

View File

@ -95,17 +95,17 @@ func TestModelDescribe(t *testing.T) {
expectDescribe: `if(mod_rev(key9)==9).then(put("key9", "99")) -> err: "failed"`,
},
{
req: txnRequest([]EtcdCondition{{Key: "key9b", ExpectedRevision: 9}}, []EtcdOperation{{Type: Put, Key: "key9b", Value: ValueOrHash{Value: "991"}}}, []EtcdOperation{{Type: Range, Key: "key9b"}}),
req: txnRequest([]EtcdCondition{{Key: "key9b", ExpectedRevision: 9}}, []EtcdOperation{{Type: PutOperation, Key: "key9b", Value: ValueOrHash{Value: "991"}}}, []EtcdOperation{{Type: RangeOperation, Key: "key9b"}}),
resp: txnResponse([]EtcdOperationResult{{}}, true, 10),
expectDescribe: `if(mod_rev(key9b)==9).then(put("key9b", "991")).else(get("key9b")) -> success(ok), rev: 10`,
},
{
req: txnRequest([]EtcdCondition{{Key: "key9c", ExpectedRevision: 9}}, []EtcdOperation{{Type: Put, Key: "key9c", Value: ValueOrHash{Value: "992"}}}, []EtcdOperation{{Type: Range, Key: "key9c"}}),
req: txnRequest([]EtcdCondition{{Key: "key9c", ExpectedRevision: 9}}, []EtcdOperation{{Type: PutOperation, Key: "key9c", Value: ValueOrHash{Value: "992"}}}, []EtcdOperation{{Type: RangeOperation, Key: "key9c"}}),
resp: txnResponse([]EtcdOperationResult{{KVs: []KeyValue{{Key: "key9c", ValueRevision: ValueRevision{Value: ValueOrHash{Value: "993"}, ModRevision: 10}}}}}, false, 10),
expectDescribe: `if(mod_rev(key9c)==9).then(put("key9c", "992")).else(get("key9c")) -> failure("993"), rev: 10`,
},
{
req: txnRequest(nil, []EtcdOperation{{Type: Range, Key: "10"}, {Type: Put, Key: "11", Value: ValueOrHash{Value: "111"}}, {Type: Delete, Key: "12"}}, nil),
req: txnRequest(nil, []EtcdOperation{{Type: RangeOperation, Key: "10"}, {Type: PutOperation, Key: "11", Value: ValueOrHash{Value: "111"}}, {Type: DeleteOperation, Key: "12"}}, nil),
resp: txnResponse([]EtcdOperationResult{{KVs: []KeyValue{{ValueRevision: ValueRevision{Value: ValueOrHash{Value: "110"}}}}}, {}, {Deleted: 1}}, true, 10),
expectDescribe: `get("10"), put("11", "111"), delete("12") -> "110", ok, deleted: 1, rev: 10`,
},

View File

@ -83,19 +83,19 @@ func initState(request EtcdRequest, response EtcdResponse) etcdState {
for i, op := range request.Txn.OperationsOnSuccess {
opResp := response.Txn.Results[i]
switch op.Type {
case Range:
case RangeOperation:
for _, kv := range opResp.KVs {
state.KeyValues[kv.Key] = ValueRevision{
Value: kv.Value,
ModRevision: kv.ModRevision,
}
}
case Put:
case PutOperation:
state.KeyValues[op.Key] = ValueRevision{
Value: op.Value,
ModRevision: response.Revision,
}
case Delete:
case DeleteOperation:
default:
panic("Unknown operation")
}
@ -147,7 +147,7 @@ func (s etcdState) step(request EtcdRequest) (etcdState, EtcdResponse) {
increaseRevision := false
for i, op := range operations {
switch op.Type {
case Range:
case RangeOperation:
opResp[i] = EtcdOperationResult{
KVs: []KeyValue{},
}
@ -176,7 +176,7 @@ func (s etcdState) step(request EtcdRequest) (etcdState, EtcdResponse) {
opResp[i].Count = 1
}
}
case Put:
case PutOperation:
_, leaseExists := s.Leases[op.LeaseID]
if op.LeaseID != 0 && !leaseExists {
break
@ -190,7 +190,7 @@ func (s etcdState) step(request EtcdRequest) (etcdState, EtcdResponse) {
if leaseExists {
s = attachToNewLease(s, op.LeaseID, op.Key)
}
case Delete:
case DeleteOperation:
if _, ok := s.KeyValues[op.Key]; ok {
delete(s.KeyValues, op.Key)
increaseRevision = true
@ -289,6 +289,14 @@ type EtcdOperation struct {
LeaseID int64
}
type OperationType string
const (
RangeOperation OperationType = "range-operation"
PutOperation OperationType = "put-operation"
DeleteOperation OperationType = "delete-operation"
)
type LeaseGrantRequest struct {
LeaseID int64
}

View File

@ -243,11 +243,11 @@ func toEtcdOperation(op clientv3.Op) EtcdOperation {
var opType OperationType
switch {
case op.IsGet():
opType = Range
opType = RangeOperation
case op.IsPut():
opType = Put
opType = PutOperation
case op.IsDelete():
opType = Delete
opType = DeleteOperation
default:
panic("Unsupported operation")
}
@ -339,7 +339,7 @@ func getRequest(key string) EtcdRequest {
}
func rangeRequest(key string, withPrefix bool, limit int64) EtcdRequest {
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: Range, Key: key, WithPrefix: withPrefix, Limit: limit}}}}
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: RangeOperation, Key: key, WithPrefix: withPrefix, Limit: limit}}}}
}
func emptyGetResponse(revision int64) EtcdNonDeterministicResponse {
@ -375,7 +375,7 @@ func unknownResponse(revision int64) EtcdNonDeterministicResponse {
}
func putRequest(key, value string) EtcdRequest {
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: Put, Key: key, Value: ToValueOrHash(value)}}}}
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: PutOperation, Key: key, Value: ToValueOrHash(value)}}}}
}
func putResponse(revision int64) EtcdNonDeterministicResponse {
@ -383,7 +383,7 @@ func putResponse(revision int64) EtcdNonDeterministicResponse {
}
func deleteRequest(key string) EtcdRequest {
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: Delete, Key: key}}}}
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: DeleteOperation, Key: key}}}}
}
func deleteResponse(deleted int64, revision int64) EtcdNonDeterministicResponse {
@ -406,7 +406,7 @@ func compareRevision(key string, expectedRevision int64) *EtcdCondition {
}
func putOperation(key, value string) *EtcdOperation {
return &EtcdOperation{Type: Put, Key: key, Value: ToValueOrHash(value)}
return &EtcdOperation{Type: PutOperation, Key: key, Value: ToValueOrHash(value)}
}
func txnRequestSingleOperation(cond *EtcdCondition, onSuccess, onFailure *EtcdOperation) EtcdRequest {
@ -442,7 +442,7 @@ func txnResponse(result []EtcdOperationResult, succeeded bool, revision int64) E
}
func putWithLeaseRequest(key, value string, leaseID int64) EtcdRequest {
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: Put, Key: key, Value: ToValueOrHash(value), LeaseID: leaseID}}}}
return EtcdRequest{Type: Txn, Txn: &TxnRequest{OperationsOnSuccess: []EtcdOperation{{Type: PutOperation, Key: key, Value: ToValueOrHash(value), LeaseID: leaseID}}}}
}
func leaseGrantRequest(leaseID int64) EtcdRequest {

View File

@ -22,14 +22,6 @@ import (
"github.com/anishathalye/porcupine"
)
type OperationType string
const (
Range OperationType = "range"
Put OperationType = "put"
Delete OperationType = "delete"
)
// NonDeterministicModel extends DeterministicModel to handle requests that have unknown or error response.
// Unknown/error response doesn't inform whether request was persisted or not, so model
// considers both cases. This is represented as multiple equally possible deterministic states.

View File

@ -264,9 +264,9 @@ func toWatchEvent(event clientv3.Event) WatchEvent {
var op model.OperationType
switch event.Type {
case mvccpb.PUT:
op = model.Put
op = model.PutOperation
case mvccpb.DELETE:
op = model.Delete
op = model.DeleteOperation
default:
panic(fmt.Sprintf("Unexpected event type: %s", event.Type))
}

View File

@ -195,24 +195,24 @@ func (t etcdTraffic) pickMultiTxnOps(ids identity.Provider) (ops []clientv3.Op)
atLeastOnePut := false
for i := 0; i < MultiOpTxnOpCount; i++ {
opTypes[i] = t.pickOperationType()
if opTypes[i] == model.Put {
if opTypes[i] == model.PutOperation {
atLeastOnePut = true
}
}
// Ensure at least one put to make operation unique
if !atLeastOnePut {
opTypes[0] = model.Put
opTypes[0] = model.PutOperation
}
for i, opType := range opTypes {
key := fmt.Sprintf("%d", keys[i])
switch opType {
case model.Range:
case model.RangeOperation:
ops = append(ops, clientv3.OpGet(key))
case model.Put:
case model.PutOperation:
value := fmt.Sprintf("%d", ids.NewRequestId())
ops = append(ops, clientv3.OpPut(key, value))
case model.Delete:
case model.DeleteOperation:
ops = append(ops, clientv3.OpDelete(key))
default:
panic("unsuported choice type")
@ -224,10 +224,10 @@ func (t etcdTraffic) pickMultiTxnOps(ids identity.Provider) (ops []clientv3.Op)
func (t etcdTraffic) pickOperationType() model.OperationType {
roll := rand.Int() % 100
if roll < 10 {
return model.Delete
return model.DeleteOperation
}
if roll < 50 {
return model.Range
return model.RangeOperation
}
return model.Put
return model.PutOperation
}

View File

@ -73,7 +73,7 @@ func lastOperationObservedInWatch(operations []porcupine.Operation, watchEvents
func matchWatchEvent(request *model.TxnRequest, watchEvents map[model.EtcdOperation]traffic.TimedWatchEvent) *traffic.TimedWatchEvent {
for _, etcdOp := range append(request.OperationsOnSuccess, request.OperationsOnFailure...) {
if etcdOp.Type == model.Put {
if etcdOp.Type == model.PutOperation {
// Remove LeaseID which is not exposed in watch.
event, ok := watchEvents[model.EtcdOperation{
Type: etcdOp.Type,
@ -90,7 +90,7 @@ func matchWatchEvent(request *model.TxnRequest, watchEvents map[model.EtcdOperat
func hasNonUniqueWriteOperation(request *model.TxnRequest) bool {
for _, etcdOp := range request.OperationsOnSuccess {
if etcdOp.Type == model.Put || etcdOp.Type == model.Delete {
if etcdOp.Type == model.PutOperation || etcdOp.Type == model.DeleteOperation {
return true
}
}
@ -99,7 +99,7 @@ func hasNonUniqueWriteOperation(request *model.TxnRequest) bool {
func hasUniqueWriteOperation(request *model.TxnRequest) bool {
for _, etcdOp := range request.OperationsOnSuccess {
if etcdOp.Type == model.Put {
if etcdOp.Type == model.PutOperation {
return true
}
}