• 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 "absl/log/log.h"
24 #include "gtest/gtest.h"
25 #include "src/core/lib/channel/channel_args.h"
26 #include "src/core/util/time.h"
27 #include "test/core/end2end/end2end_tests.h"
28 
29 namespace grpc_core {
30 
OneRequestAndShutdownServer(CoreEnd2endTest & test)31 static void OneRequestAndShutdownServer(CoreEnd2endTest& test) {
32   LOG(ERROR) << "Create client side call";
33   auto c = test.NewClientCall("/service/method")
34                .Timeout(Duration::Seconds(30))
35                .Create();
36   IncomingMetadata server_initial_md;
37   IncomingStatusOnClient server_status;
38   LOG(ERROR) << "Start initial batch";
39   c.NewBatch(1)
40       .SendInitialMetadata({})
41       .SendCloseFromClient()
42       .RecvInitialMetadata(server_initial_md)
43       .RecvStatusOnClient(server_status);
44   auto s = test.RequestCall(101);
45   test.Expect(101, true);
46   test.Step();
47   test.ShutdownServerAndNotify(1000);
48   IncomingCloseOnServer client_closed;
49   s.NewBatch(102)
50       .SendInitialMetadata({})
51       .SendStatusFromServer(GRPC_STATUS_UNIMPLEMENTED, "xyz", {})
52       .RecvCloseOnServer(client_closed);
53   test.Expect(102, true);
54   test.Expect(1, true);
55   test.Expect(1000, true);
56   test.Step();
57   // Please refer https://github.com/grpc/grpc/issues/21221 for additional
58   // details.
59   // TODO(yashykt@) - The following line should be removable after C-Core
60   // correctly handles GOAWAY frames. Internal Reference b/135458602. If this
61   // test remains flaky even after this, an alternative fix would be to send a
62   // request when the server is in the shut down state.
63   test.Step();
64 
65   EXPECT_EQ(server_status.status(), GRPC_STATUS_UNIMPLEMENTED);
66   EXPECT_EQ(server_status.message(), "xyz");
67   EXPECT_EQ(s.method(), "/service/method");
68   EXPECT_FALSE(client_closed.was_cancelled());
69 }
70 
CORE_END2END_TEST(CoreClientChannelTest,DisappearingServer)71 CORE_END2END_TEST(CoreClientChannelTest, DisappearingServer) {
72   SKIP_IF_V3();
73   OneRequestAndShutdownServer(*this);
74   InitServer(ChannelArgs());
75   OneRequestAndShutdownServer(*this);
76 }
77 
78 }  // namespace grpc_core
79