Debian Codegraph @

test/core/promise/try_seq_metadata_test.cc

raw
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 <memory>
16
17 #include "absl/types/variant.h"
18 #include "gtest/gtest.h"
19
20 #include <grpc/event_engine/memory_allocator.h>
21 #include <grpc/status.h>
22
23 #include "src/core/lib/gprpp/ref_counted_ptr.h"
24 #include "src/core/lib/promise/poll.h"
25 #include "src/core/lib/promise/try_seq.h"
26 #include "src/core/lib/resource_quota/arena.h"
27 #include "src/core/lib/resource_quota/memory_quota.h"
28 #include "src/core/lib/resource_quota/resource_quota.h"
29 #include "src/core/lib/transport/metadata_batch.h"
30
31 namespace grpc_core {
32
33 static auto* g_memory_allocator = new MemoryAllocator(
34 ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
35
36 struct TestMap : public MetadataMap<TestMap, GrpcStatusMetadata> {
37 using MetadataMap<TestMap, GrpcStatusMetadata>::MetadataMap;
38 };
39
40 TEST(PromiseTest, SucceedAndThenFail) {
41 auto arena = MakeScopedArena(1024, g_memory_allocator);
42 Poll<TestMap> r = TrySeq(
43 [&arena] {
44 TestMap m(arena.get());
45 m.Set(GrpcStatusMetadata(), GRPC_STATUS_OK);
46 return m;
47 },
48 [&arena]() {
49 TestMap m(arena.get());
50 m.Set(GrpcStatusMetadata(), GRPC_STATUS_UNAVAILABLE);
51 return m;
52 })();
53 EXPECT_EQ(absl::get<TestMap>(r).get(GrpcStatusMetadata()),
54 GRPC_STATUS_UNAVAILABLE);
55 }
56
57 } // namespace grpc_core
58
59 int main(int argc, char** argv) {
60 ::testing::InitGoogleTest(&argc, argv);
61 return RUN_ALL_TESTS();
62 }