• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include <grpc/status.h>
20 
21 #include <memory>
22 
23 #include "gtest/gtest.h"
24 #include "src/core/lib/slice/slice.h"
25 #include "src/core/util/time.h"
26 #include "test/core/end2end/end2end_tests.h"
27 
28 namespace grpc_core {
29 
30 namespace {
RequestResponseWithPayload(CoreEnd2endTest & test)31 void RequestResponseWithPayload(CoreEnd2endTest& test) {
32   // Create large request and response bodies. These are big enough to require
33   // multiple round trips to deliver to the peer, and their exact contents of
34   // will be verified on completion.
35   auto request_slice = RandomSlice(1024 * 1024);
36   auto response_slice = RandomSlice(1024 * 1024);
37 
38   auto c = test.NewClientCall("/foo").Timeout(Duration::Seconds(60)).Create();
39 
40   IncomingMetadata server_initial_md;
41   IncomingMessage server_message;
42   IncomingStatusOnClient server_status;
43   c.NewBatch(1)
44       .SendInitialMetadata({})
45       .SendMessage(request_slice.Ref())
46       .SendCloseFromClient()
47       .RecvInitialMetadata(server_initial_md)
48       .RecvMessage(server_message)
49       .RecvStatusOnClient(server_status);
50 
51   CoreEnd2endTest::IncomingCall s = test.RequestCall(101);
52   test.Expect(101, true);
53   test.Step();
54 
55   IncomingMessage client_message;
56   s.NewBatch(102).SendInitialMetadata({}).RecvMessage(client_message);
57   test.Expect(102, true);
58   test.Step();
59 
60   IncomingCloseOnServer client_close;
61   s.NewBatch(103)
62       .RecvCloseOnServer(client_close)
63       .SendMessage(response_slice.Ref())
64       .SendStatusFromServer(GRPC_STATUS_OK, "xyz", {});
65   test.Expect(103, true);
66   test.Expect(1, true);
67   test.Step();
68 
69   EXPECT_EQ(server_status.status(), GRPC_STATUS_OK);
70   EXPECT_EQ(server_status.message(), "xyz");
71   EXPECT_EQ(s.method(), "/foo");
72   EXPECT_FALSE(client_close.was_cancelled());
73   EXPECT_EQ(client_message.payload(), request_slice);
74   EXPECT_EQ(server_message.payload(), response_slice);
75 }
76 }  // namespace
77 
78 // Client sends a request with payload, server reads then returns a response
79 // payload and status.
CORE_END2END_TEST(CoreLargeSendTest,RequestResponseWithPayload)80 CORE_END2END_TEST(CoreLargeSendTest, RequestResponseWithPayload) {
81   RequestResponseWithPayload(*this);
82 }
83 
CORE_END2END_TEST(CoreLargeSendTest,RequestResponseWithPayload10Times)84 CORE_END2END_TEST(CoreLargeSendTest, RequestResponseWithPayload10Times) {
85   for (int i = 0; i < 10; i++) {
86     RequestResponseWithPayload(*this);
87   }
88 }
89 
90 }  // namespace grpc_core
91