From 201b5bad89ce861c3db395939080aa00dae98a85 Mon Sep 17 00:00:00 2001 From: isabelsavannah Date: Fri, 21 Dec 2018 14:10:16 -0800 Subject: [PATCH] KEP-937: status request should keep session open --- mocks/mock_node_base.hpp | 8 ++++---- node/node.cpp | 16 ++++++++-------- node/node.hpp | 4 ++-- node/node_base.hpp | 6 ++++-- pbft/pbft.cpp | 8 ++++---- pbft/test/pbft_audit_test.cpp | 8 ++++---- pbft/test/pbft_catchup_test.cpp | 10 +++++----- pbft/test/pbft_checkpoint_tests.cpp | 2 +- pbft/test/pbft_join_leave_test.cpp | 26 +++++++++++++------------- pbft/test/pbft_newview_test.cpp | 4 ++-- pbft/test/pbft_proto_test.cpp | 10 +++++----- pbft/test/pbft_test.cpp | 26 +++++++++++++------------- pbft/test/pbft_timestamp_test.cpp | 16 ++++++++-------- pbft/test/pbft_viewchange_test.cpp | 26 +++++++++++++------------- 14 files changed, 86 insertions(+), 84 deletions(-) diff --git a/mocks/mock_node_base.hpp b/mocks/mock_node_base.hpp index 320003ff..35e4f5ff 100644 --- a/mocks/mock_node_base.hpp +++ b/mocks/mock_node_base.hpp @@ -32,10 +32,10 @@ class Mocknode_base : public node_base { void()); MOCK_METHOD2(send_message_json, void(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg)); - MOCK_METHOD2(send_message, - void(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg)); - MOCK_METHOD2(send_message_str, - void(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg)); + MOCK_METHOD3(send_message, + void(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session)); + MOCK_METHOD3(send_message_str, + void(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session)); }; } // namespace bzn diff --git a/node/node.cpp b/node/node.cpp index 374c1452..6ba748ae 100644 --- a/node/node.cpp +++ b/node/node.cpp @@ -165,12 +165,12 @@ node::priv_protobuf_handler(const bzn_envelope& msg, std::shared_ptr msg) +node::send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session) { if (this->chaos->is_message_delayed()) { const boost::asio::ip::tcp::endpoint ep_copy = ep; - this->chaos->reschedule_message(std::bind(&node::send_message_str, shared_from_this(), std::move(ep_copy), std::move(msg))); + this->chaos->reschedule_message(std::bind(&node::send_message_str, shared_from_this(), std::move(ep_copy), std::move(msg), close_session)); return; } @@ -182,7 +182,7 @@ node::send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr std::shared_ptr socket = this->io_context->make_unique_tcp_socket(); socket->async_connect(ep, - [self = shared_from_this(), socket, ep, msg](const boost::system::error_code& ec) + [self = shared_from_this(), socket, ep, msg, close_session](const boost::system::error_code& ec) { if (ec) { @@ -195,7 +195,7 @@ node::send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr std::shared_ptr ws = self->websocket->make_unique_websocket_stream(socket->get_tcp_socket()); ws->async_handshake(ep.address().to_string(), "/", - [self, ws, msg](const boost::system::error_code& ec) + [self, ws, msg, close_session](const boost::system::error_code& ec) { if (ec) { @@ -209,7 +209,7 @@ node::send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr std::bind(&node::priv_protobuf_handler, self, std::placeholders::_1, std::placeholders::_2)); // send the message requested... - session->send_message(msg, true); + session->send_message(msg, close_session); }); }); } @@ -217,11 +217,11 @@ node::send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr void node::send_message_json(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg) { - this->send_message_str(ep, std::make_shared(msg->toStyledString())); + this->send_message_str(ep, std::make_shared(msg->toStyledString()), true); } void -node::send_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg) +node::send_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session) { if(msg->sender().empty()) { @@ -233,5 +233,5 @@ node::send_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptrcrypto->sign(*msg); } - this->send_message_str(ep, std::make_shared(msg->SerializeAsString())); + this->send_message_str(ep, std::make_shared(msg->SerializeAsString()), close_session); } diff --git a/node/node.hpp b/node/node.hpp index 576f85bf..4f99281a 100644 --- a/node/node.hpp +++ b/node/node.hpp @@ -42,9 +42,9 @@ namespace bzn void send_message_json(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg) override; - void send_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg) override; + void send_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session) override; - void send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg) override; + void send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session) override; private: FRIEND_TEST(node, test_that_registered_message_handler_is_invoked); diff --git a/node/node_base.hpp b/node/node_base.hpp index 82b6b180..3f9e7932 100644 --- a/node/node_base.hpp +++ b/node/node_base.hpp @@ -60,15 +60,17 @@ namespace bzn * signature fields, if not already set. * @param ep host to send the message to * @param msg message to send + * @param close_session don't expect a response on this session */ - virtual void send_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg) = 0; + virtual void send_message(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session) = 0; /** * Convenience method to connect and send a message to a node. Will set sender and signature fields as appropriate. * @param ep host to send the message to * @param msg message to send + * @param close_session don't expect a response on this session */ - virtual void send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg) = 0; + virtual void send_message_str(const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr msg, bool close_session) = 0; }; } // bzn diff --git a/pbft/pbft.cpp b/pbft/pbft.cpp index 9a8c843d..79d618d5 100644 --- a/pbft/pbft.cpp +++ b/pbft/pbft.cpp @@ -329,7 +329,7 @@ void pbft::forward_request_to_primary(const bzn_envelope& request_env) { LOG(info) << "Forwarding request to primary"; - this->node->send_message(bzn::make_endpoint(this->get_primary()), std::make_shared(request_env)); + this->node->send_message(bzn::make_endpoint(this->get_primary()), std::make_shared(request_env), true); const bzn::hash_t req_hash = this->crypto->hash(request_env); @@ -561,7 +561,7 @@ pbft::broadcast(const bzn_envelope& msg) for (const auto& peer : this->current_peers()) { - this->node->send_message(make_endpoint(peer), msg_ptr); + this->node->send_message(make_endpoint(peer), msg_ptr, true); } } @@ -908,7 +908,7 @@ pbft::request_checkpoint_state(const checkpoint_t& cp) // TODO: fix the race condition here where receiving node may not have had time to // stabilize its checkpoint yet. auto msg_ptr = std::make_shared(this->wrap_message(msg)); - this->node->send_message(make_endpoint(selected), msg_ptr); + this->node->send_message(make_endpoint(selected), msg_ptr, false); } const peer_address_t& @@ -1722,7 +1722,7 @@ pbft::join_swarm() LOG(info) << "Sending request to join swarm to node " << this->current_peers()[selected].uuid; auto msg_ptr = std::make_shared(this->wrap_message(join_msg)); - this->node->send_message(make_endpoint(this->current_peers()[selected]), msg_ptr); + this->node->send_message(make_endpoint(this->current_peers()[selected]), msg_ptr, false); // TODO: set timer and retry with different peer if we don't get a response #else diff --git a/pbft/test/pbft_audit_test.cpp b/pbft/test/pbft_audit_test.cpp index 4eac99a6..81be8917 100644 --- a/pbft/test/pbft_audit_test.cpp +++ b/pbft/test/pbft_audit_test.cpp @@ -17,9 +17,9 @@ namespace bzn::test { TEST_F(pbft_test, test_local_commit_sends_audit_messages) { - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(false)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(false)), _)) .Times(AnyNumber()); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->build_pbft(); @@ -47,7 +47,7 @@ namespace bzn::test TEST_F(pbft_test, primary_sends_primary_status) { - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->build_pbft(); @@ -59,7 +59,7 @@ namespace bzn::test TEST_F(pbft_test, nonprimary_does_not_send_primary_status) { - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_audit, Eq(true)), _)) .Times(Exactly(0)); this->uuid = SECOND_NODE_UUID; diff --git a/pbft/test/pbft_catchup_test.cpp b/pbft/test/pbft_catchup_test.cpp index 7641d238..d579288e 100644 --- a/pbft/test/pbft_catchup_test.cpp +++ b/pbft/test/pbft_catchup_test.cpp @@ -108,7 +108,7 @@ namespace bzn this->build_pbft(); // node shouldn't be sending any checkpoint messages right now - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_checkpoint, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_checkpoint, Eq(true)), _)) .Times((Exactly(0))); auto nodes = TEST_PEER_LIST.begin(); @@ -121,7 +121,7 @@ namespace bzn // one more checkpoint message and the node should request state from a random node auto primary = this->pbft->get_primary(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)), _)) .Times((Exactly(1))); bzn::peer_address_t node(*nodes++); @@ -140,7 +140,7 @@ namespace bzn } // since the node has this checkpoint it should NOT request state for it - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)), _)) .Times((Exactly(0))); stabilize_checkpoint(100); } @@ -171,7 +171,7 @@ namespace bzn // get the node to request state auto primary = this->pbft->get_primary(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)), _)) .Times((Exactly(1))); auto nodes = TEST_PEER_LIST.begin(); @@ -204,7 +204,7 @@ namespace bzn // get the node to request state auto primary = this->pbft->get_primary(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_get_state, Eq(true)), _)) .Times((Exactly(1))); auto nodes = TEST_PEER_LIST.begin(); diff --git a/pbft/test/pbft_checkpoint_tests.cpp b/pbft/test/pbft_checkpoint_tests.cpp index 707ad1db..ac0fd714 100644 --- a/pbft/test/pbft_checkpoint_tests.cpp +++ b/pbft/test/pbft_checkpoint_tests.cpp @@ -47,7 +47,7 @@ namespace bzn::test TEST_F(pbft_checkpoint_test, test_checkpoint_messages_sent_on_execute) { - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_checkpoint, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_checkpoint, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->build_pbft(); diff --git a/pbft/test/pbft_join_leave_test.cpp b/pbft/test/pbft_join_leave_test.cpp index f3b1834f..112ceaf9 100644 --- a/pbft/test/pbft_join_leave_test.cpp +++ b/pbft/test/pbft_join_leave_test.cpp @@ -111,7 +111,7 @@ namespace bzn { EXPECT_CALL(*(mock_node), send_message(bzn::make_endpoint(p), - AllOf(message_has_correct_req_hash(expect_hash), message_has_correct_pbft_type(PBFT_MSG_PREPARE)))) + AllOf(message_has_correct_req_hash(expect_hash), message_has_correct_pbft_type(PBFT_MSG_PREPARE)), _)) .Times(Exactly(1)); } @@ -198,7 +198,7 @@ namespace bzn EXPECT_CALL(*(this->mock_node), send_message(bzn::make_endpoint(p), AllOf(message_has_req_with_correct_type(bzn_envelope::kPbftInternalRequest), - message_has_correct_pbft_type(PBFT_MSG_PREPREPARE)))) + message_has_correct_pbft_type(PBFT_MSG_PREPREPARE)), _)) .Times(Exactly(1)); } @@ -227,7 +227,7 @@ namespace bzn EXPECT_CALL(*(this->mock_node), send_message(bzn::make_endpoint(p), AllOf(message_has_req_with_correct_type(bzn_envelope::kPbftInternalRequest), - message_has_correct_pbft_type(PBFT_MSG_PREPREPARE)))) + message_has_correct_pbft_type(PBFT_MSG_PREPREPARE)), _)) .Times(Exactly(1)); } @@ -301,7 +301,7 @@ namespace bzn EXPECT_CALL(*(mock_node), send_message(bzn::make_endpoint(p), AllOf(message_has_correct_req_hash(msg.request_hash()), - message_has_correct_pbft_type(PBFT_MSG_COMMIT)))) + message_has_correct_pbft_type(PBFT_MSG_COMMIT)), _)) .Times(Exactly(1)); } @@ -340,7 +340,7 @@ namespace bzn EXPECT_CALL(*(mock_node), send_message(bzn::make_endpoint(p), AllOf(message_has_correct_req_hash(msg.request_hash()), - message_has_correct_pbft_type(PBFT_MSG_COMMIT)))) + message_has_correct_pbft_type(PBFT_MSG_COMMIT)), _)) .Times(Exactly(1)); } @@ -394,9 +394,9 @@ namespace bzn TEST_F(pbft_join_leave_test, DISABLED_node_not_in_swarm_asks_to_join) { this->uuid = "somenode"; - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_join, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_join, Eq(true)), _)) .Times(Exactly(1)) - .WillOnce(Invoke([&](auto, auto) + .WillOnce(Invoke([&](auto, auto, bool /*close_session*/) { pbft_membership_msg response; response.set_type(PBFT_MMSG_JOIN_RESPONSE); @@ -409,7 +409,7 @@ namespace bzn TEST_F(pbft_join_leave_test, node_in_swarm_doesnt_ask_to_join) { - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_join, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_join, Eq(true)), _)) .Times(Exactly(0)); this->build_pbft(); } @@ -422,9 +422,9 @@ namespace bzn for (auto const &p : TEST_PEER_LIST) { EXPECT_CALL(*(this->mock_node), - send_message(bzn::make_endpoint(p), ResultOf(test::is_preprepare, Eq(true)))) + send_message(bzn::make_endpoint(p), ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(1)) - .WillOnce(Invoke([&](auto, auto &envelope) + .WillOnce(Invoke([&](auto, auto &envelope, bool /*close_session*/) { pbft_msg msg; EXPECT_TRUE(msg.ParseFromString(envelope->pbft())); @@ -432,7 +432,7 @@ namespace bzn if (p.uuid == TEST_NODE_UUID) { EXPECT_CALL(*(mock_node), - send_message(_, ResultOf(test::is_prepare, Eq(true)))) + send_message(_, ResultOf(test::is_prepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); // reflect the pre-prepare back @@ -455,9 +455,9 @@ namespace bzn for (auto const &p : TEST_PEER_LIST) { EXPECT_CALL(*(this->mock_node), - send_message(bzn::make_endpoint(p), ResultOf(test::is_commit, Eq(true)))) + send_message(bzn::make_endpoint(p), ResultOf(test::is_commit, Eq(true)), _)) .Times(Exactly(1)) - .WillOnce(Invoke([&](auto, auto &wmsg) + .WillOnce(Invoke([&](auto, auto &wmsg, bool /*close_session*/) { pbft_msg msg; EXPECT_TRUE(msg.ParseFromString(wmsg->pbft())); diff --git a/pbft/test/pbft_newview_test.cpp b/pbft/test/pbft_newview_test.cpp index a3c8eac5..d22d040f 100644 --- a/pbft/test/pbft_newview_test.cpp +++ b/pbft/test/pbft_newview_test.cpp @@ -81,8 +81,8 @@ namespace bzn this->run_transaction_through_primary_times(2, current_sequence); bzn_envelope viewchange_envelope; - EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)))) - .WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto& viewchange_env) {viewchange_envelope = *viewchange_env;})); + EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)), _)) + .WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto& viewchange_env, bool /*close_session*/) {viewchange_envelope = *viewchange_env;})); this->pbft->handle_failure(); pbft_msg viewchange; diff --git a/pbft/test/pbft_proto_test.cpp b/pbft/test/pbft_proto_test.cpp index 94aeccea..303d09a0 100644 --- a/pbft/test/pbft_proto_test.cpp +++ b/pbft/test/pbft_proto_test.cpp @@ -31,9 +31,9 @@ namespace bzn { // after request is sent, SUT will send out pre-prepares to all nodes auto operation = std::shared_ptr(); - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())) - .WillRepeatedly(Invoke([&](auto, auto wmsg) + .WillRepeatedly(Invoke([&](auto, auto wmsg, bool /*close_session*/) { pbft_msg msg; if (msg.ParseFromString(wmsg->pbft())) @@ -68,7 +68,7 @@ namespace bzn pbft_proto_test::send_preprepare(uint64_t sequence, const bzn_envelope& request) { // after preprepare is sent, SUT will send out prepares to all nodes - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_prepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_prepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); auto peer = *(TEST_PEER_LIST.begin()); @@ -88,7 +88,7 @@ namespace bzn pbft_proto_test::send_prepares(uint64_t sequence, const bzn::hash_t& request_hash) { // after prepares are sent, SUT will send out commits to all nodes - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_commit, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_commit, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); for (const auto& peer : TEST_PEER_LIST) @@ -139,7 +139,7 @@ namespace bzn })); // after enough commits are sent, SUT will send out checkpoint message to all nodes - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_checkpoint, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_checkpoint, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); } diff --git a/pbft/test/pbft_test.cpp b/pbft/test/pbft_test.cpp index 1dadbbeb..18174524 100644 --- a/pbft/test/pbft_test.cpp +++ b/pbft/test/pbft_test.cpp @@ -34,7 +34,7 @@ namespace bzn::test TEST_F(pbft_test, test_requests_fire_preprepare) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_preprepare, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); pbft->handle_database_message(this->request_msg, this->mock_session); @@ -42,8 +42,8 @@ namespace bzn::test TEST_F(pbft_test, test_forwarded_to_primary_when_not_primary) { - EXPECT_CALL(*mock_node, send_message(_, A>())).Times(1).WillRepeatedly(Invoke( - [&](auto ep, auto msg) + EXPECT_CALL(*mock_node, send_message(_, A>(), _)).Times(1).WillRepeatedly(Invoke( + [&](auto ep, auto msg, bool /*close_session*/) { EXPECT_EQ(ep, make_endpoint(this->pbft->get_primary())); EXPECT_EQ(msg->payload_case(), bzn_envelope::kDatabaseMsg); @@ -60,7 +60,7 @@ namespace bzn::test std::set seen_sequences; void - save_sequences(const boost::asio::ip::tcp::endpoint& /*ep*/, std::shared_ptr wrapped_msg) + save_sequences(const boost::asio::ip::tcp::endpoint& /*ep*/, std::shared_ptr wrapped_msg, bool /*close_session*/) { pbft_msg msg; msg.ParseFromString(wrapped_msg->pbft()); @@ -71,7 +71,7 @@ namespace bzn::test TEST_F(pbft_test, test_different_requests_get_different_sequences) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, _)).WillRepeatedly(Invoke(save_sequences)); + EXPECT_CALL(*mock_node, send_message(_, _, _)).WillRepeatedly(Invoke(save_sequences)); database_msg req, req2; req.mutable_header()->set_nonce(5); @@ -86,7 +86,7 @@ namespace bzn::test TEST_F(pbft_test, test_preprepare_triggers_prepare) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->pbft->handle_message(this->preprepare_msg, default_original_msg); @@ -96,7 +96,7 @@ namespace bzn::test { this->build_pbft(); std::shared_ptr wrapped_msg; - EXPECT_CALL(*mock_node, send_message(_, _)).WillRepeatedly(SaveArg<1>(&wrapped_msg)); + EXPECT_CALL(*mock_node, send_message(_, _, _)).WillRepeatedly(SaveArg<1>(&wrapped_msg)); this->pbft->handle_message(this->preprepare_msg, default_original_msg); @@ -110,7 +110,7 @@ namespace bzn::test TEST_F(pbft_test, test_wrong_view_preprepare_rejected) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, _)).Times(Exactly(0)); + EXPECT_CALL(*mock_node, send_message(_, _, _)).Times(Exactly(0)); pbft_msg preprepare2(this->preprepare_msg); preprepare2.set_view(6); @@ -121,7 +121,7 @@ namespace bzn::test TEST_F(pbft_test, test_no_duplicate_prepares_same_sequence_number) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, _)).Times(Exactly(TEST_PEER_LIST.size())); + EXPECT_CALL(*mock_node, send_message(_, _, _)).Times(Exactly(TEST_PEER_LIST.size())); pbft_msg preprepare2(this->preprepare_msg); preprepare2.set_request_hash("some other hash"); @@ -133,9 +133,9 @@ namespace bzn::test TEST_F(pbft_test, test_commit_messages_sent) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_commit, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_commit, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->pbft->handle_message(this->preprepare_msg, default_original_msg); @@ -202,7 +202,7 @@ namespace bzn::test TEST_F(pbft_test, messages_after_high_water_mark_dropped) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)), _)) .Times(Exactly(0)); this->preprepare_msg.set_sequence(pbft->get_high_water_mark() + 1); @@ -212,7 +212,7 @@ namespace bzn::test TEST_F(pbft_test, messages_before_low_water_mark_dropped) { this->build_pbft(); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(is_prepare, Eq(true)), _)) .Times(Exactly(0)); this->preprepare_msg.set_sequence(this->pbft->get_low_water_mark()); diff --git a/pbft/test/pbft_timestamp_test.cpp b/pbft/test/pbft_timestamp_test.cpp index d73fab24..6d87857b 100644 --- a/pbft/test/pbft_timestamp_test.cpp +++ b/pbft/test/pbft_timestamp_test.cpp @@ -39,14 +39,14 @@ namespace bzn request->set_sender(TEST_NODE_UUID); // the first time we should get pre-prepare messages - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->handle_request(*request); auto request2 = new bzn_envelope(*request); // this time no pre-prepare should be issued - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(0)); this->handle_request(*request2); } @@ -69,7 +69,7 @@ namespace bzn request->set_sender(TEST_NODE_UUID); // we should get pre-prepare messages - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->handle_request(*request); @@ -79,7 +79,7 @@ namespace bzn request2->set_timestamp(request2->timestamp() + 1); // again we should get pre-prepare messages - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->handle_request(*request2); @@ -95,7 +95,7 @@ namespace bzn request3->set_database_msg(dmsg3->SerializeAsString()); // again we should get pre-prepare messages - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->handle_request(*request3); } @@ -118,7 +118,7 @@ namespace bzn request->set_sender(TEST_NODE_UUID); // we should get pre-prepare messages - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->handle_request(*request); @@ -127,7 +127,7 @@ namespace bzn request2->set_sender(SECOND_NODE_UUID); // again we should get pre-prepare messages - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); this->handle_request(*request2); } @@ -149,7 +149,7 @@ namespace bzn request->set_sender(TEST_NODE_UUID); // we should NOT get pre-prepare messages since this is an old request - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_preprepare, Eq(true)), _)) .Times(Exactly(0)); this->handle_request(*request); } diff --git a/pbft/test/pbft_viewchange_test.cpp b/pbft/test/pbft_viewchange_test.cpp index 0079f728..bd43e602 100644 --- a/pbft/test/pbft_viewchange_test.cpp +++ b/pbft/test/pbft_viewchange_test.cpp @@ -162,9 +162,9 @@ namespace bzn this->run_transaction_through_primary_times(2, current_sequence); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)))) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)), _)) .WillRepeatedly(Invoke( - [&](const auto & /*endpoint*/, const auto &viewchange_env) + [&](const auto & /*endpoint*/, const auto &viewchange_env, bool /*close_session*/) { pbft_msg viewchange; viewchange.ParseFromString(viewchange_env->pbft()); @@ -206,8 +206,8 @@ namespace bzn this->run_transaction_through_primary_times(2, current_sequence); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)))) - .WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto viewchange_env) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)), _)) + .WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto viewchange_env, bool /*close_session*/) { EXPECT_EQ(this->pbft->get_uuid(), viewchange_env->sender()); pbft_msg viewchange; @@ -239,8 +239,8 @@ namespace bzn this->uuid = SECOND_NODE_UUID; this->build_pbft(); - EXPECT_CALL(*mock_node, send_message_str(_, _)) - .WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto encoded_message) + EXPECT_CALL(*mock_node, send_message_str(_, _, _)) + .WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto encoded_message, bool /*close_session*/) { bzn_envelope envelope; envelope.ParseFromString(*encoded_message); @@ -377,9 +377,9 @@ namespace bzn for (auto const &p : TEST_PEER_LIST) { EXPECT_CALL(*(this->mock_node), - send_message(bzn::make_endpoint(p), ResultOf(test::is_viewchange, Eq(true)))) + send_message(bzn::make_endpoint(p), ResultOf(test::is_viewchange, Eq(true)), _)) .Times(Exactly(1)) - .WillRepeatedly(Invoke([&](auto, auto wmsg) + .WillRepeatedly(Invoke([&](auto, auto wmsg, bool /*close_session*/) { pbft_msg msg; ASSERT_TRUE(msg.ParseFromString(wmsg->pbft())); @@ -391,13 +391,13 @@ namespace bzn for (auto const &p : TEST_PEER_LIST) { - EXPECT_CALL(*mock_node2, send_message(bzn::make_endpoint(p), ResultOf(test::is_newview, Eq(true)))) + EXPECT_CALL(*mock_node2, send_message(bzn::make_endpoint(p), ResultOf(test::is_newview, Eq(true)), _)) .Times(Exactly(1)) - .WillRepeatedly(Invoke([&](auto, auto wmsg) + .WillRepeatedly(Invoke([&](auto, auto wmsg, bool /*close_session*/) { if (p.uuid == TEST_NODE_UUID) { - EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_prepare, Eq(true)))) + EXPECT_CALL(*this->mock_node, send_message(_, ResultOf(test::is_prepare, Eq(true)), _)) .Times(Exactly(2 * TEST_PEER_LIST.size())); pbft_msg msg; ASSERT_TRUE(msg.ParseFromString(wmsg->pbft())); @@ -406,7 +406,7 @@ namespace bzn })); } - EXPECT_CALL(*mock_node2, send_message(_, ResultOf(test::is_viewchange, Eq(true)))) + EXPECT_CALL(*mock_node2, send_message(_, ResultOf(test::is_viewchange, Eq(true)), _)) .Times(Exactly(TEST_PEER_LIST.size())); // get sut1 to generate viewchange message @@ -428,7 +428,7 @@ namespace bzn EXPECT_CALL(*mock_crypto, hash(An())).WillRepeatedly(Invoke([&](const bzn_envelope& envelope) {return envelope.sender() + "_" + std::to_string(current_sequence) + "_" + std::to_string(envelope.timestamp());})); - EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)))).WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto &viewchange_env) + EXPECT_CALL(*mock_node, send_message(_, ResultOf(test::is_viewchange, Eq(true)), _)).WillRepeatedly(Invoke([&](const auto & /*endpoint*/, const auto &viewchange_env, bool /*close_session*/) { original_message = *viewchange_env; })); this->run_transaction_through_primary_times(1, current_sequence);