Skip to content

Commit

Permalink
e2e: test request bytes both for server and client sides
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Dec 20, 2017
1 parent 433c3ef commit e19e863
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"net/url"
"os"
"strconv"
"strings"

"github.com/coreos/etcd/etcdserver"
Expand Down Expand Up @@ -117,6 +118,8 @@ type etcdProcessClusterConfig struct {
quotaBackendBytes int64
noStrictReconfig bool
initialCorruptCheck bool

maxRequestBytes int
}

// newEtcdProcessCluster launches a new cluster from etcd processes, returning
Expand Down Expand Up @@ -222,6 +225,10 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro
"--quota-backend-bytes", fmt.Sprintf("%d", cfg.quotaBackendBytes),
)
}
if cfg.maxRequestBytes > 0 {
args = append(args,
"--max-request-bytes", strconv.Itoa(cfg.maxRequestBytes))
}
if cfg.noStrictReconfig {
args = append(args, "--strict-reconfig-check=false")
}
Expand Down
38 changes: 38 additions & 0 deletions e2e/ctl_v3_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,44 @@ func putTest(cx ctlCtx) {
}
}

func TestCtlV3PutRequestTooLarge(t *testing.T) {
cfg := configNoTLS
cfg.maxRequestBytes = 15
testCtl(t, func(cx ctlCtx) {
exp := "Error: etcdserver: request is too large"
cmdArgs := append(cx.PrefixArgs(), "put", "foo", strings.Repeat("a", 30))
if err := spawnWithExpect(cmdArgs, exp); err != nil {
cx.t.Fatalf("expected %q, got %q", exp, err.Error())
}
}, withCfg(cfg))
}

func TestCtlV3PutSendLimit(t *testing.T) {
testCtl(t, func(cx ctlCtx) {
exp := "Error: rpc error: code = ResourceExhausted desc = grpc: trying to send message larger than max (37 vs. 10)"
cmdArgs := append(cx.PrefixArgs(), "get", "foo", strings.Repeat("a", 30))
if err := spawnWithExpect(cmdArgs, exp); err != nil {
cx.t.Fatalf("expected %q, got %q", exp, err.Error())
}
}, withCfg(configNoTLS), withMaxSendBytes(10))
}

func TestCtlV3GetRecvLimit(t *testing.T) {
testCtl(t, func(cx ctlCtx) {
for i := range []int{0, 1, 2} {
if err := ctlV3Put(cx, fmt.Sprintf("foo%d", i), "bar", ""); err != nil {
fmt.Println(i, err)
cx.t.Fatal(err)
}
}
exp := "Error: rpc error: code = ResourceExhausted desc = grpc: received message larger than max (86 vs. 30)"
cmdArgs := append(cx.PrefixArgs(), "get", "foo", "--prefix")
if err := spawnWithExpect(cmdArgs, exp); err != nil {
cx.t.Fatalf("expected %q, got %q", exp, err.Error())
}
}, withCfg(configNoTLS), withMaxSendBytes(20), withMaxRecvBytes(30))
}

func putTestIgnoreValue(cx ctlCtx) {
if err := ctlV3Put(cx, "foo", "bar", ""); err != nil {
cx.t.Fatal(err)
Expand Down
18 changes: 18 additions & 0 deletions e2e/ctl_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package e2e
import (
"fmt"
"os"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -64,6 +65,9 @@ type ctlCtx struct {

dialTimeout time.Duration

maxSendBytes int
maxRecvBytes int

quorum bool // if true, set up 3-node cluster and linearizable read
interactive bool

Expand Down Expand Up @@ -93,6 +97,14 @@ func withDialTimeout(timeout time.Duration) ctlOption {
return func(cx *ctlCtx) { cx.dialTimeout = timeout }
}

func withMaxSendBytes(n int) ctlOption {
return func(cx *ctlCtx) { cx.maxSendBytes = n }
}

func withMaxRecvBytes(n int) ctlOption {
return func(cx *ctlCtx) { cx.maxRecvBytes = n }
}

func withQuorum() ctlOption {
return func(cx *ctlCtx) { cx.quorum = true }
}
Expand Down Expand Up @@ -185,6 +197,12 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string {
fmap := make(map[string]string)
fmap["endpoints"] = strings.Join(eps, ",")
fmap["dial-timeout"] = cx.dialTimeout.String()
if cx.maxSendBytes > 0 {
fmap["max-send-bytes"] = strconv.Itoa(cx.maxSendBytes)
}
if cx.maxRecvBytes > 0 {
fmap["max-recv-bytes"] = strconv.Itoa(cx.maxRecvBytes)
}
if cx.epc.cfg.clientTLS == clientTLS {
if cx.epc.cfg.isClientAutoTLS {
fmap["insecure-transport"] = "false"
Expand Down

0 comments on commit e19e863

Please sign in to comment.