arena_promise_test.cc
Go to the documentation of this file.
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 
16 
17 #include <memory>
18 
19 #include "absl/types/variant.h"
20 #include "gtest/gtest.h"
21 
23 
28 
29 namespace grpc_core {
30 
32  ResourceQuota::Default()->memory_quota()->CreateMemoryAllocator("test"));
33 
34 TEST(ArenaPromiseTest, AllocatedWorks) {
37  int x = 42;
38  ArenaPromise<int> p([x] { return Poll<int>(x); });
39  EXPECT_EQ(p(), Poll<int>(42));
40  p = ArenaPromise<int>([] { return Poll<int>(43); });
41  EXPECT_EQ(p(), Poll<int>(43));
42 }
43 
44 TEST(ArenaPromiseTest, DestructionWorks) {
47  auto x = std::make_shared<int>(42);
48  auto p = ArenaPromise<int>([x] { return Poll<int>(*x); });
50  EXPECT_EQ(q(), Poll<int>(42));
51 }
52 
53 TEST(ArenaPromiseTest, MoveAssignmentWorks) {
56  auto x = std::make_shared<int>(42);
57  auto p = ArenaPromise<int>([x] { return Poll<int>(*x); });
58  p = ArenaPromise<int>();
59 }
60 
61 } // namespace grpc_core
62 
63 int main(int argc, char** argv) {
64  ::testing::InitGoogleTest(&argc, argv);
65  return RUN_ALL_TESTS();
66 }
grpc_core::MakeScopedArena
ScopedArenaPtr MakeScopedArena(size_t initial_size, MemoryAllocator *memory_allocator)
Definition: src/core/lib/resource_quota/arena.h:130
grpc_event_engine::experimental::MemoryAllocator
Definition: memory_allocator.h:35
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::TEST
TEST(AvlTest, NoOp)
Definition: avl_test.cc:21
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::TestContext
Definition: activity_test.cc:248
test_context.h
arena_promise.h
grpc_core::g_memory_allocator
static auto * g_memory_allocator
Definition: call_finalization_test.cc:24
grpc_core::ResourceQuota::Default
static ResourceQuotaRefPtr Default()
Definition: resource_quota.cc:27
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
resource_quota.h
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::ArenaPromise
Definition: arena_promise.h:152
ref_counted_ptr.h
memory_quota.h
memory_allocator.h
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
main
int main(int argc, char **argv)
Definition: arena_promise_test.cc:63
absl::variant
Definition: abseil-cpp/absl/types/internal/variant.h:46


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:42