1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/core/lib/channel/call_finalization.h"
16
17 #include <grpc/event_engine/memory_allocator.h>
18
19 #include <memory>
20 #include <string>
21
22 #include "absl/strings/str_cat.h"
23 #include "gtest/gtest.h"
24 #include "src/core/lib/resource_quota/memory_quota.h"
25 #include "src/core/lib/resource_quota/resource_quota.h"
26 #include "src/core/util/ref_counted_ptr.h"
27 #include "test/core/promise/test_context.h"
28
29 namespace grpc_core {
30
TEST(CallFinalizationTest,Works)31 TEST(CallFinalizationTest, Works) {
32 auto arena = SimpleArenaAllocator()->MakeArena();
33 std::string evidence;
34 TestContext<Arena> context(arena.get());
35 CallFinalization finalization;
36 auto p = std::make_shared<int>(42);
37 finalization.Add([&evidence, p](const grpc_call_final_info* final_info) {
38 evidence += absl::StrCat("FIRST", final_info->error_string, *p, "\n");
39 });
40 finalization.Add([&evidence, p](const grpc_call_final_info* final_info) {
41 evidence += absl::StrCat("SECOND", final_info->error_string, *p, "\n");
42 });
43 grpc_call_final_info final_info{};
44 final_info.error_string = "123";
45 finalization.Run(&final_info);
46 EXPECT_EQ(evidence, "SECOND12342\nFIRST12342\n");
47 }
48
49 } // namespace grpc_core
50
main(int argc,char ** argv)51 int main(int argc, char** argv) {
52 ::testing::InitGoogleTest(&argc, argv);
53 return RUN_ALL_TESTS();
54 }
55