1 // Copyright 2023 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 #ifndef GRPC_TEST_CORE_END2END_FIXTURES_INPROC_FIXTURE_H 16 #define GRPC_TEST_CORE_END2END_FIXTURES_INPROC_FIXTURE_H 17 18 #include <grpc/grpc.h> 19 20 #include "absl/functional/any_invocable.h" 21 #include "src/core/ext/transport/inproc/inproc_transport.h" 22 #include "src/core/lib/channel/channel_args.h" 23 #include "test/core/end2end/end2end_tests.h" 24 25 class InprocFixture : public grpc_core::CoreTestFixture { 26 public: InprocFixture(bool promise_based)27 explicit InprocFixture(bool promise_based) : promise_based_(promise_based) {} 28 29 private: MakeServer(const grpc_core::ChannelArgs & args,grpc_completion_queue * cq,absl::AnyInvocable<void (grpc_server *)> & pre_server_start)30 grpc_server* MakeServer( 31 const grpc_core::ChannelArgs& args, grpc_completion_queue* cq, 32 absl::AnyInvocable<void(grpc_server*)>& pre_server_start) override { 33 if (made_server_ != nullptr) return made_server_; 34 made_server_ = grpc_server_create( 35 args.Set("grpc.experimental.promise_based_inproc_transport", 36 promise_based_) 37 .ToC() 38 .get(), 39 nullptr); 40 grpc_server_register_completion_queue(made_server_, cq, nullptr); 41 pre_server_start(made_server_); 42 grpc_server_start(made_server_); 43 return made_server_; 44 } MakeClient(const grpc_core::ChannelArgs & args,grpc_completion_queue * cq)45 grpc_channel* MakeClient(const grpc_core::ChannelArgs& args, 46 grpc_completion_queue* cq) override { 47 // Registered method registration isn't going to work for tests that create 48 // the client first and use inproc transports. 49 absl::AnyInvocable<void(grpc_server*)> 50 not_sure_what_to_do_but_this_works_for_now = [](grpc_server*) {}; 51 return grpc_inproc_channel_create( 52 MakeServer(args, cq, not_sure_what_to_do_but_this_works_for_now), 53 args.Set("grpc.experimental.promise_based_inproc_transport", 54 promise_based_) 55 .ToC() 56 .get(), 57 nullptr); 58 } 59 60 grpc_server* made_server_ = nullptr; 61 const bool promise_based_; 62 }; 63 64 #endif // GRPC_TEST_CORE_END2END_FIXTURES_INPROC_FIXTURE_H 65