Skip to content

Commit

Permalink
test: Add client test for initiating finish during read
Browse files Browse the repository at this point in the history
  • Loading branch information
Tradias committed Feb 27, 2025
1 parent c25743f commit 0ae8586
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/agrpc/server_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ class ServerRPCBidiStreamingBase<ResponderT<ResponseT, RequestT>, TraitsT, Execu
/**
* @brief Receive a message from the client
*
* May not be called currently with `finish()`/`write_and_finish()`. It is not meaningful to call it concurrently
* with another read on the same rpc since reads on the same stream are delivered in order.
* It may not be called concurrently with operations other than `write()`. It is not meaningful to call it
* concurrently with another read on the same rpc since reads on the same stream are delivered in order.
*
* @param token A completion token like `asio::yield_context` or `agrpc::use_sender`. The completion signature is
* `void(bool)`. `true` indicates that a valid message was read. `false` when there will be no more incoming
Expand Down
32 changes: 31 additions & 1 deletion test/src/test_client_rpc_17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ TEST_CASE_FIXTURE(ClientRPCTest<test::ClientStreamingClientRPC>, "ClientStreamin
}

TEST_CASE_FIXTURE(ClientRPCIoContextTest<test::BidirectionalStreamingClientRPC>,
"BidirectionalStreamingClientRPC concurrent read+write")
"BidirectionalStreamingClientRPC initiate write during read")
{
bool set_last_message{};
SUBCASE("no WriteOptions") {}
Expand Down Expand Up @@ -355,6 +355,36 @@ TEST_CASE_FIXTURE(ClientRPCIoContextTest<test::BidirectionalStreamingClientRPC>,
});
}

TEST_CASE_FIXTURE(ClientRPCIoContextTest<test::BidirectionalStreamingClientRPC>,
"BidirectionalStreamingClientRPC initiate finish during read")
{
run_server_client_on_separate_threads(
[&](auto& rpc, const asio::yield_context& yield)
{
CHECK(rpc.finish(grpc::Status{grpc::StatusCode::ALREADY_EXISTS, ""}, yield));
},
[&](const asio::yield_context& yield)
{
auto rpc = create_rpc();
start_rpc(rpc, yield);
std::promise<bool> promise;
bool read{};
rpc.read_initial_metadata(
[&](auto&& ok)
{
read = ok;
});
rpc.read(response,
[&](bool ok)
{
promise.set_value(ok);
});
CHECK_EQ(grpc::StatusCode::ALREADY_EXISTS, rpc.finish(yield).error_code());
CHECK_FALSE(promise.get_future().get());
CHECK(read);
});
}

TEST_CASE_FIXTURE(ClientRPCIoContextTest<test::BidirectionalStreamingClientRPC>,
"BidirectionalStreamingClientRPC cancel before write+read")
{
Expand Down
2 changes: 1 addition & 1 deletion test/src/test_server_rpc_17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ TEST_CASE_TEMPLATE("ServerRPC/ClientRPC bidi streaming success", RPC, test::Bidi
}

TEST_CASE_FIXTURE(ServerRPCTest<test::BidirectionalStreamingServerRPC>,
"BidirectionalStreamingServerRPC concurrent read+finish")
"BidirectionalStreamingServerRPC initiate finish during read")
{
bool order{};
register_and_perform_requests(
Expand Down

0 comments on commit 0ae8586

Please sign in to comment.