21 #include <condition_variable>
28 #include <gtest/gtest.h>
41 #include "src/proto/grpc/testing/echo.grpc.pb.h"
63 return out <<
"TestScenario{protocol="
65 <<
"," <<
scenario.credentials_type <<
"}";
69 std::ostringstream
out;
74 class ContextAllocatorEnd2endTestBase
77 static void SetUpTestCase() {
grpc_init(); }
79 ContextAllocatorEnd2endTestBase() {}
81 ~ContextAllocatorEnd2endTestBase()
override =
default;
83 void SetUp()
override { GetParam().Log(); }
85 void CreateServer(std::unique_ptr<grpc::ContextAllocator> context_allocator) {
101 void DestroyServer() {
109 ChannelArguments
args;
115 channel_creds,
args);
126 void TearDown()
override {
133 void SendRpcs(
int num_rpcs) {
135 for (
int i = 0;
i < num_rpcs;
i++) {
138 ClientContext cli_ctx;
141 request.set_message(test_string);
146 std::condition_variable
cv;
148 stub_->async()->Echo(
154 std::lock_guard<std::mutex>
l(
mu);
158 std::unique_lock<std::mutex>
l(
mu);
167 std::unique_ptr<EchoTestService::Stub>
stub_;
173 class DefaultContextAllocatorTest :
public ContextAllocatorEnd2endTestBase {};
175 TEST_P(DefaultContextAllocatorTest, SimpleRpc) {
176 const int kRpcCount = 10;
182 class NullContextAllocatorTest :
public ContextAllocatorEnd2endTestBase {
187 std::atomic<int>* deallocation_count)
195 GenericCallbackServerContext* NewGenericCallbackServerContext()
override {
206 GenericCallbackServerContext* )
216 TEST_P(NullContextAllocatorTest, UnaryRpc) {
217 const int kRpcCount = 10;
219 std::atomic<int> deallocation_count{0};
220 std::unique_ptr<NullAllocator> allocator(
229 EXPECT_EQ(kRpcCount, deallocation_count);
232 class SimpleContextAllocatorTest :
public ContextAllocatorEnd2endTestBase {
237 std::atomic<int>* deallocation_count)
244 GenericCallbackServerContext* NewGenericCallbackServerContext()
override {
246 return new GenericCallbackServerContext();
252 delete callback_server_context;
255 void Release(GenericCallbackServerContext* generic_callback_server_context)
258 delete generic_callback_server_context;
266 TEST_P(SimpleContextAllocatorTest, UnaryRpc) {
267 const int kRpcCount = 10;
269 std::atomic<int> deallocation_count{0};
270 std::unique_ptr<SimpleAllocator> allocator(
279 EXPECT_EQ(kRpcCount, deallocation_count);
284 std::vector<std::string> credentials_types{
292 if (test_insecure && insec_ok()) {
298 for (Protocol p : parr) {
299 for (
const auto& cred : credentials_types) {
314 DefaultContextAllocatorTest,
325 int main(
int argc,
char** argv) {