Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tcp_client::init bug fix #135

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/util/rpc/tcp_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace cbdc::rpc {
/// starts the response handler thread.
/// \return true.
[[nodiscard]] auto init() -> bool {
if(!m_net.cluster_connect(m_server_endpoints, false)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this line a few weeks ago and i was banging my head trying to figure out what i was missing!

if(!m_net.cluster_connect(m_server_endpoints, true)) {
return false;
}

Expand Down
10 changes: 1 addition & 9 deletions tests/unit/coordinator/controller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "uhs/twophase/coordinator/controller.hpp"
#include "uhs/twophase/locking_shard/controller.hpp"
#include "util.hpp"

#include <gtest/gtest.h>
Expand Down Expand Up @@ -56,12 +57,3 @@ TEST_F(coordinator_controller_test, out_of_range_node_id) {
m_logger);
ASSERT_FALSE(m_ctl_coordinator->init());
}

TEST_F(coordinator_controller_test, successful_init) {
m_ctl_coordinator
= std::make_unique<cbdc::coordinator::controller>(0,
0,
m_opts,
m_logger);
ASSERT_TRUE(m_ctl_coordinator->init());
}
2 changes: 1 addition & 1 deletion tests/unit/rpc/tcp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ TEST(tcp_rpc_test, send_fail_test) {
auto client = cbdc::rpc::tcp_client<request, response>(
{{cbdc::network::localhost, 55555},
{cbdc::network::localhost, 55556}});
ASSERT_TRUE(client.init());
ASSERT_FALSE(client.init());

auto req = request{0};
auto resp = client.call(req);
Expand Down
57 changes: 57 additions & 0 deletions tests/unit/sentinel_2pc/controller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,60 @@ TEST_F(sentinel_2pc_test, tx_validation_test) {
});
ASSERT_TRUE(res);
}

TEST_F(sentinel_2pc_test, bad_coordinator_endpoint) {
// Replace the valid coordinator endpoint defined in the fixture
// with an invalid endpoint.
m_opts.m_coordinator_endpoints.clear();
const auto bad_coordinator_ep
= std::make_pair("abcdefg", m_coordinator_port);
m_opts.m_coordinator_endpoints.resize(1);
m_opts.m_coordinator_endpoints[0].push_back(bad_coordinator_ep);

// Initialize a new controller with the invalid coordinator endpoint.
auto ctl = std::make_unique<cbdc::sentinel_2pc::controller>(0,
m_opts,
m_logger);

// Check that the controller with the invalid coordinator endpoint
// fails to initialize correctly.
ASSERT_FALSE(ctl->init());
}

TEST_F(sentinel_2pc_test, bad_sentinel_client_endpoint) {
// Test that a sentinel client fails to initialize
// when given a bad endpoint.
constexpr auto bad_endpoint = std::make_pair("abcdefg", m_sentinel_port);
const std::vector<cbdc::network::endpoint_t> bad_endpoints{bad_endpoint};
auto client = cbdc::sentinel::rpc::client(bad_endpoints, m_logger);
ASSERT_FALSE(client.init());

// Test that the controller fails to initialize when given a bad endpoint
// for a sentinel client.
m_opts.m_sentinel_endpoints.emplace_back(bad_endpoint);
auto ctl = std::make_unique<cbdc::sentinel_2pc::controller>(0,
m_opts,
m_logger);
ASSERT_FALSE(ctl->init());
}

TEST_F(sentinel_2pc_test, bad_rpc_server_endpoint) {
// The sentinel endpoint defined below (which corresponds to sentinel_id
// also defined below) is used by the sentinel_2pc controller to initialize
// an rpc server. Replacing the valid endpoint defined in the fixture with
// an invalid endpoint should cause the rpc server to fail to initialize.
m_opts.m_sentinel_endpoints.clear();
constexpr auto bad_endpoint = std::make_pair("abcdefg", m_sentinel_port);
m_opts.m_sentinel_endpoints.resize(1);
m_opts.m_sentinel_endpoints.emplace_back(bad_endpoint);

// Initialize a new controller with the invalid endpoint for the server.
constexpr uint32_t sentinel_id = 0;
const auto ctl
= std::make_unique<cbdc::sentinel_2pc::controller>(sentinel_id,
m_opts,
m_logger);

// Check that the controller with the invalid endpoint fails to initialize.
ASSERT_FALSE(ctl->init());
}