From e19e8633fbb17911afec0940cb06860626a79dc4 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Wed, 20 Dec 2017 00:07:44 -0800 Subject: [PATCH] e2e: test request bytes both for server and client sides Signed-off-by: Gyuho Lee --- e2e/cluster_test.go | 7 +++++++ e2e/ctl_v3_kv_test.go | 38 ++++++++++++++++++++++++++++++++++++++ e2e/ctl_v3_test.go | 18 ++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/e2e/cluster_test.go b/e2e/cluster_test.go index 69896dd48d51..9e2fce4eb61a 100644 --- a/e2e/cluster_test.go +++ b/e2e/cluster_test.go @@ -19,6 +19,7 @@ import ( "io/ioutil" "net/url" "os" + "strconv" "strings" "github.com/coreos/etcd/etcdserver" @@ -117,6 +118,8 @@ type etcdProcessClusterConfig struct { quotaBackendBytes int64 noStrictReconfig bool initialCorruptCheck bool + + maxRequestBytes int } // newEtcdProcessCluster launches a new cluster from etcd processes, returning @@ -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") } diff --git a/e2e/ctl_v3_kv_test.go b/e2e/ctl_v3_kv_test.go index 2e14bea6416a..3ef4cc70a249 100644 --- a/e2e/ctl_v3_kv_test.go +++ b/e2e/ctl_v3_kv_test.go @@ -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) diff --git a/e2e/ctl_v3_test.go b/e2e/ctl_v3_test.go index 396e6c184175..d76e1d8d9fad 100644 --- a/e2e/ctl_v3_test.go +++ b/e2e/ctl_v3_test.go @@ -17,6 +17,7 @@ package e2e import ( "fmt" "os" + "strconv" "strings" "testing" "time" @@ -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 @@ -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 } } @@ -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"