mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #14907 from fuweid/chore-reduce-ifelse
chore: use Getter in WarnOfExpensiveReadOnlyTxnRequest
This commit is contained in:
commit
6d0bf24e54
@ -61,10 +61,10 @@ func WarnOfExpensiveReadOnlyTxnRequest(lg *zap.Logger, warningApplyDuration time
|
||||
if !isNil(txnResponse) {
|
||||
var resps []string
|
||||
for _, r := range txnResponse.Responses {
|
||||
switch op := r.Response.(type) {
|
||||
switch r.Response.(type) {
|
||||
case *pb.ResponseOp_ResponseRange:
|
||||
if op.ResponseRange != nil {
|
||||
resps = append(resps, fmt.Sprintf("range_response_count:%d", len(op.ResponseRange.Kvs)))
|
||||
if op := r.GetResponseRange(); op != nil {
|
||||
resps = append(resps, fmt.Sprintf("range_response_count:%d", len(op.GetKvs())))
|
||||
} else {
|
||||
resps = append(resps, "range_response:nil")
|
||||
}
|
||||
|
@ -19,12 +19,19 @@ import (
|
||||
"time"
|
||||
|
||||
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
|
||||
"go.etcd.io/etcd/api/v3/mvccpb"
|
||||
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
// TestWarnOfExpensiveReadOnlyTxnRequest verifies WarnOfExpensiveReadOnlyTxnRequest
|
||||
// never panic no matter what data the txnResponse contains.
|
||||
func TestWarnOfExpensiveReadOnlyTxnRequest(t *testing.T) {
|
||||
kvs := []*mvccpb.KeyValue{
|
||||
&mvccpb.KeyValue{Key: []byte("k1"), Value: []byte("v1")},
|
||||
&mvccpb.KeyValue{Key: []byte("k2"), Value: []byte("v2")},
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
txnResp *pb.TxnResponse
|
||||
@ -35,7 +42,9 @@ func TestWarnOfExpensiveReadOnlyTxnRequest(t *testing.T) {
|
||||
Responses: []*pb.ResponseOp{
|
||||
{
|
||||
Response: &pb.ResponseOp_ResponseRange{
|
||||
ResponseRange: &pb.RangeResponse{},
|
||||
ResponseRange: &pb.RangeResponse{
|
||||
Kvs: kvs,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -60,6 +69,13 @@ func TestWarnOfExpensiveReadOnlyTxnRequest(t *testing.T) {
|
||||
ResponseRange: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
Response: &pb.ResponseOp_ResponseRange{
|
||||
ResponseRange: &pb.RangeResponse{
|
||||
Kvs: kvs,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user