Skip to content

Commit

Permalink
rpcdaemon: fix warning in StateChanges stream unit test (#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
canepat authored Apr 26, 2024
1 parent b509b8c commit 230fcbf
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions silkworm/rpc/ethdb/kv/state_changes_stream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TEST_CASE_METHOD(StateChangesStreamTest, "StateChangesStream::open", "[rpc][ethd
TEST_CASE_METHOD(StateChangesStreamTest, "StateChangesStream::run", "[rpc][ethdb][kv][state_changes_stream]") {
RegistrationIntervalGuard guard{std::chrono::milliseconds{10}};

SECTION("stream closed-by-peer/reopened/cancelled") {
SECTION("stream closed-by-peer") {
// Set the call expectations:
// 1. remote::KV::StubInterface::PrepareAsyncStateChangesRaw calls succeed
EXPECT_CALL(*stub_, PrepareAsyncStateChangesRaw)
Expand All @@ -110,29 +110,6 @@ TEST_CASE_METHOD(StateChangesStreamTest, "StateChangesStream::run", "[rpc][ethdb
.WillOnce(test::finish_streaming_aborted(grpc_context_));
});

return statechanges_reader_ptr_.release();
}))
.WillOnce(InvokeWithoutArgs([&]() {
// Recreate mocked reader for StateChanges RPC because StateChanges RPC has been *recreated*
statechanges_reader_ptr_ = std::make_unique<StrictMockKVStateChangesAsyncReader>();
statechanges_reader_ = statechanges_reader_ptr_.get();

// 2. AsyncReader<remote::StateChangeBatch>::StartCall call succeed
EXPECT_CALL(*statechanges_reader_, StartCall)
.WillOnce([&](void* tag) {
agrpc::process_grpc_tag(grpc_context_, tag, true);

// 3. AsyncReader<remote::StateChangeBatch>::Read 1st/2nd/3rd calls succeed, 4th fails
EXPECT_CALL(*statechanges_reader_, Read)
.WillOnce(test::read_success_with(grpc_context_, make_batch()))
.WillOnce(test::read_success_with(grpc_context_, make_batch()))
.WillOnce(test::read_success_with(grpc_context_, make_batch()))
.WillOnce(test::read_failure(grpc_context_));
// 4. AsyncReader<remote::StateChangeBatch>::Finish call succeeds w/ status cancelled
EXPECT_CALL(*statechanges_reader_, Finish)
.WillOnce(test::finish_streaming_cancelled(grpc_context_));
});

return statechanges_reader_ptr_.release();
}));

Expand All @@ -145,8 +122,8 @@ TEST_CASE_METHOD(StateChangesStreamTest, "StateChangesStream::run", "[rpc][ethdb
expect_request_async_statechanges(/*.ok=*/true);
// 2. AsyncReader<remote::StateChangeBatch>::Read call fails
EXPECT_CALL(*statechanges_reader_, Read).WillOnce(test::read_failure(grpc_context_));
// 3. AsyncReader<remote::StateChangeBatch>::Finish call succeeds w/ status cancelled
EXPECT_CALL(*statechanges_reader_, Finish).WillOnce(test::finish_streaming_cancelled(grpc_context_));
// 3. AsyncReader<remote::StateChangeBatch>::Finish call succeeds w/ status aborted
EXPECT_CALL(*statechanges_reader_, Finish).WillOnce(test::finish_streaming_aborted(grpc_context_));

// Execute the test: running the stream should succeed until finishes
CHECK_NOTHROW(spawn_and_wait(stream_.run()));
Expand All @@ -159,8 +136,8 @@ TEST_CASE_METHOD(StateChangesStreamTest, "StateChangesStream::run", "[rpc][ethdb
EXPECT_CALL(*statechanges_reader_, Read)
.WillOnce(test::read_success_with(grpc_context_, make_batch()))
.WillOnce(test::read_failure(grpc_context_));
// 3. AsyncReader<remote::StateChangeBatch>::Finish call succeeds w/ status cancelled
EXPECT_CALL(*statechanges_reader_, Finish).WillOnce(test::finish_streaming_cancelled(grpc_context_));
// 3. AsyncReader<remote::StateChangeBatch>::Finish call succeeds w/ status aborted
EXPECT_CALL(*statechanges_reader_, Finish).WillOnce(test::finish_streaming_aborted(grpc_context_));

// Execute the test: running the stream should succeed until finishes
CHECK_NOTHROW(spawn_and_wait(stream_.run()));
Expand Down

0 comments on commit 230fcbf

Please sign in to comment.