Skip to content

Commit

Permalink
Add test for bad rpc server endpoint
Browse files Browse the repository at this point in the history
Previously, there was a bug that made it impossible to trigger the error
"Failed to start sentinel RPC server" in sentinel::rpc::init.
With the bug fixed, the error can now be triggered.  This commit adds
a unit test that specifically triggers the error.

Signed-off-by: Michael L. Szulczewski <[email protected]>
  • Loading branch information
mszulcz-mitre committed Jun 26, 2022
1 parent 175ed0b commit 55d3e70
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/unit/sentinel_2pc/controller_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,24 @@ TEST_F(sentinel_2pc_test, bad_sentinel_client_endpoint) {
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.push_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());
}

0 comments on commit 55d3e70

Please sign in to comment.