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