Skip to content

Commit

Permalink
test: Fix invalid server/clientRPC tests and remove virtual inheritan…
Browse files Browse the repository at this point in the history
…ce from GrpcGenericClientServerTest
  • Loading branch information
Tradias committed Oct 14, 2023
1 parent 915dfb1 commit 5d36a1b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
32 changes: 13 additions & 19 deletions test/src/test_client_rpc_17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,20 @@ TEST_CASE_TEMPLATE("Streaming RPC::start returns false on error", RPC, test::Cli
test.grpc_context.run();
}

TEST_CASE_FIXTURE(ClientRPCTest<test::ServerStreamingClientRPC>,
"UnaryClientRPC::request exception thrown from completion handler rethrows from GrpcContext.run()")
TEST_CASE_FIXTURE(
ClientRPCRequestResponseTest<test::ServerStreamingClientRPC>,
"ServerStreamingClientRPC::start exception thrown from completion handler rethrows from GrpcContext.run()")
{
CHECK_THROWS_AS(register_and_perform_three_requests(
[&](auto& rpc, auto&, const asio::yield_context& yield)
{
rpc.finish(grpc::Status::OK, yield);
},
[&](Request& request, Response& response, const asio::yield_context& yield)
{
auto rpc = std::make_unique<ClientRPC>(grpc_context, test::set_default_deadline);
start_rpc(*rpc, request, response, yield);
auto& r = *rpc;
r.read(response, asio::bind_executor(test::InlineExecutor{},
[r = std::move(rpc)](bool)
{
throw test::Exception{};
}));
}),
test::Exception);
server->Shutdown();
test::ServerStreamingClientRPC rpc{get_executor()};
rpc.context().set_deadline(test::ten_milliseconds_from_now());
start_rpc(rpc, request, response,
asio::bind_executor(grpc_context,
[&](bool)
{
throw test::Exception{};
}));
CHECK_THROWS_AS(grpc_context.run(), test::Exception);
}

TEST_CASE_TEMPLATE("ClientRPC::read_initial_metadata on cancelled RPC", RPC, test::ClientStreamingClientRPC,
Expand Down
4 changes: 2 additions & 2 deletions test/src/test_server_rpc_20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ TEST_CASE_FIXTURE(ServerRPCAwaitableTest<test::ServerStreamingServerRPC>,
std::exception_ptr eptr;
agrpc::register_awaitable_request_handler<ServerRPC>(
get_executor(), service,
[&](test::ServerStreamingServerRPC& rpc, test::msg::Request&) -> asio::awaitable<void>
[&](test::ServerStreamingServerRPC&, test::msg::Request&) -> asio::awaitable<void>
{
throw test::Exception{};
co_return;
Expand Down Expand Up @@ -542,7 +542,7 @@ TEST_CASE_FIXTURE(ServerRPCAwaitableTest<test::ServerStreamingServerRPC>,
signal.emit(asio::cancellation_type::total);
perform_requests_in_order(just_finish(*this), just_finish(*this, grpc::StatusCode::DEADLINE_EXCEEDED,
test::two_hundred_milliseconds_from_now()));
CHECK_THROWS(std::rethrow_exception(eptr));
CHECK_FALSE(eptr);
}
#endif
#endif
1 change: 1 addition & 0 deletions test/utils/utils/client_rpc_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <doctest/doctest.h>

#include <functional>
#include <type_traits>

#if defined(AGRPC_STANDALONE_ASIO) || defined(AGRPC_BOOST_ASIO)
#include <agrpc/register_yield_request_handler.hpp>
Expand Down
7 changes: 4 additions & 3 deletions test/utils/utils/grpc_client_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
namespace test
{
GrpcClientServerTest::GrpcClientServerTest()
: server_context_lifetime(std::in_place), server_context(*server_context_lifetime)
: stub(test::v1::Test::NewStub(channel)),
server_context_lifetime(std::in_place),
server_context(*server_context_lifetime)
{
builder.RegisterService(&service);
this->server = builder.BuildAndStart();
stub = test::v1::Test::NewStub(this->channel);
server = builder.BuildAndStart();
}

GrpcClientServerTest::~GrpcClientServerTest()
Expand Down
4 changes: 2 additions & 2 deletions test/utils/utils/grpc_generic_client_server_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
namespace test
{
GrpcGenericClientServerTest::GrpcGenericClientServerTest()
: stub{std::make_unique<grpc::GenericStub>(this->channel)},
: stub{std::make_unique<grpc::GenericStub>(channel)},
server_context_lifetime(std::in_place),
server_context(*server_context_lifetime)
{
builder.RegisterAsyncGenericService(&service);
this->server = builder.BuildAndStart();
server = builder.BuildAndStart();
}

GrpcGenericClientServerTest::~GrpcGenericClientServerTest()
Expand Down
2 changes: 1 addition & 1 deletion test/utils/utils/grpc_generic_client_server_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace test
{
struct GrpcGenericClientServerTest : virtual test::GrpcClientServerTestBase
struct GrpcGenericClientServerTest : test::GrpcClientServerTestBase
{
grpc::AsyncGenericService service;
std::unique_ptr<grpc::GenericStub> stub;
Expand Down

0 comments on commit 5d36a1b

Please sign in to comment.