From 9830b4faada11c0d4f2dadc1a0bab77b687181d2 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Tue, 19 Dec 2017 15:21:01 -0800 Subject: [PATCH] clientv3/integration: test large KV requests Signed-off-by: Gyuho Lee --- clientv3/integration/kv_test.go | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/clientv3/integration/kv_test.go b/clientv3/integration/kv_test.go index f41b952976b7..aacac5320d3b 100644 --- a/clientv3/integration/kv_test.go +++ b/clientv3/integration/kv_test.go @@ -861,3 +861,46 @@ func TestKVPutAtMostOnce(t *testing.T) { t.Fatalf("expected version <= 10, got %+v", resp.Kvs[0]) } } + +// TestKVLargeRequests ensures that configurable MaxRequestBytes +// works as intended for clients. +func TestKVLargeRequests(t *testing.T) { + defer testutil.AfterTest(t) + tests := []struct { + maxRequestBytes uint + valueSize int + expectError error + }{ + {1, 1024, rpctypes.ErrRequestTooLarge}, + + // without proper client-side receive size limit + // "code = ResourceExhausted desc = grpc: received message larger than max (5242929 vs. 4194304)" + {7 * 1024 * 1024, 5 * 1024 * 1024, nil}, + + {10 * 1024 * 1024, 10 * 1024 * 1024, rpctypes.ErrRequestTooLarge}, + {10 * 1024 * 1024, 10*1024*1024 + 5, rpctypes.ErrRequestTooLarge}, + } + for i, test := range tests { + clus := integration.NewClusterV3(t, + &integration.ClusterConfig{ + Size: 1, + MaxRequestBytes: test.maxRequestBytes, + }, + ) + cli := clus.Client(0) + _, err := cli.Put(context.TODO(), "foo", strings.Repeat("a", test.valueSize)) + if err != test.expectError { + t.Errorf("#%d: expected %v, got %v", i, test.expectError, err) + } + + // put request went through, now expects large response back + if err == nil { + _, err = cli.Get(context.TODO(), "foo") + if err != nil { + t.Errorf("#%d: get expected no error, got %v", i, err) + } + } + + clus.Terminate(t) + } +}