From b4e1def08cb0766519bddbd93523f404090dc55f Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Mon, 22 May 2017 16:56:17 -0700 Subject: [PATCH] clientv3/integration: add TestV3PutLargeRequests to integration --- integration/cluster.go | 10 ++++++++++ integration/v3_grpc_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/integration/cluster.go b/integration/cluster.go index 3278bc232ddd..ab66ab0c0f62 100644 --- a/integration/cluster.go +++ b/integration/cluster.go @@ -36,6 +36,7 @@ import ( "github.com/coreos/etcd/client" "github.com/coreos/etcd/clientv3" + "github.com/coreos/etcd/embed" "github.com/coreos/etcd/etcdserver" "github.com/coreos/etcd/etcdserver/api/v2http" "github.com/coreos/etcd/etcdserver/api/v3client" @@ -60,6 +61,8 @@ const ( basePort = 21000 UrlScheme = "unix" UrlSchemeTLS = "unixs" + + defaultMaxRequestSize ) var ( @@ -93,6 +96,7 @@ type ClusterConfig struct { DiscoveryURL string UseGRPC bool QuotaBackendBytes int64 + MaxRequestBytes uint } type cluster struct { @@ -224,6 +228,7 @@ func (c *cluster) mustNewMember(t *testing.T) *member { peerTLS: c.cfg.PeerTLS, clientTLS: c.cfg.ClientTLS, quotaBackendBytes: c.cfg.QuotaBackendBytes, + maxRequestBytes: c.cfg.MaxRequestBytes, }) m.DiscoveryURL = c.cfg.DiscoveryURL if c.cfg.UseGRPC { @@ -490,6 +495,7 @@ type memberConfig struct { peerTLS *transport.TLSInfo clientTLS *transport.TLSInfo quotaBackendBytes int64 + maxRequestBytes uint } // mustNewMember return an inited member with the given name. If peerTLS is @@ -537,6 +543,10 @@ func mustNewMember(t *testing.T, mcfg memberConfig) *member { m.ElectionTicks = electionTicks m.TickMs = uint(tickDuration / time.Millisecond) m.QuotaBackendBytes = mcfg.quotaBackendBytes + m.MaxRequestBytes = mcfg.maxRequestBytes + if m.MaxRequestBytes == 0 { + m.MaxRequestBytes = embed.DefaultMaxRequestBytes + } m.AuthToken = "simple" // for the purpose of integration testing, simple token is enough return m } diff --git a/integration/v3_grpc_test.go b/integration/v3_grpc_test.go index ac6d66467e4e..3d74bcfaf43b 100644 --- a/integration/v3_grpc_test.go +++ b/integration/v3_grpc_test.go @@ -1625,6 +1625,34 @@ func TestGRPCStreamRequireLeader(t *testing.T) { } } +// TestV3PutLargeRequests ensures that configurable MaxRequestBytes works as intended. +func TestV3PutLargeRequests(t *testing.T) { + defer testutil.AfterTest(t) + tests := []struct { + key string + maxRequestBytes uint + valueSize int + expectError bool + }{ + // don't set to 0. use 0 as the default. + {"foo", 1, 1024, true}, + {"foo", 10 * 1024 * 1024, 9 * 1024 * 1024, false}, + {"foo", 10 * 1024 * 1024, 10 * 1024 * 1024, true}, + {"foo", 10 * 1024 * 1024, 11 * 1024 * 1024, true}, + } + for _, test := range tests { + clus := NewClusterV3(t, &ClusterConfig{Size: 1, MaxRequestBytes: test.maxRequestBytes}) + kvcli := toGRPC(clus.Client(0)).KV + reqput := &pb.PutRequest{Key: []byte(test.key), Value: make([]byte, test.valueSize)} + _, err := kvcli.Put(context.TODO(), reqput) + hasError := (err != nil) + if hasError != test.expectError { + t.Fatalf("expected error? %v, but got %v case:[%+v] \n", test.expectError, hasError, test) + } + clus.Terminate(t) + } +} + func eqErrGRPC(err1 error, err2 error) bool { return !(err1 == nil && err2 != nil) || err1.Error() == err2.Error() }