Skip to content

Commit

Permalink
Update tests for additional connector/acceptor parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 6, 2024
1 parent db3f9fa commit 243444e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 17 deletions.
9 changes: 6 additions & 3 deletions test/net/acceptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ BOOST_AUTO_TEST_CASE(acceptor__construct__default__stopped_expected)
{
const logger log{};
threadpool pool(1);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
const settings set(bc::system::chain::selection::mainnet);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);

BOOST_REQUIRE(&instance->get_settings() == &set);
BOOST_REQUIRE(&instance->get_service() == &pool.service());
Expand All @@ -74,9 +75,10 @@ BOOST_AUTO_TEST_CASE(acceptor__start__stop__success)
{
const logger log{};
threadpool pool(1);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
const settings set(bc::system::chain::selection::mainnet);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);

// Result codes inconsistent due to context.
instance->start(42);
Expand All @@ -96,9 +98,10 @@ BOOST_AUTO_TEST_CASE(acceptor__accept__stop__channel_stopped)
// TODO: There is no way to fake successful acceptance.
const logger log{};
threadpool pool(2);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
settings set(bc::system::chain::selection::mainnet);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);

// Result codes inconsistent due to context.
instance->start(42);
Expand Down
18 changes: 12 additions & 6 deletions test/net/connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ BOOST_AUTO_TEST_CASE(connector__construct__default__stopped_expected)
logger log{};
log.stop();
threadpool pool(1);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
const settings set(bc::system::chain::selection::mainnet);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);

BOOST_REQUIRE(&instance->get_settings() == &set);
BOOST_REQUIRE(&instance->get_service() == &pool.service());
Expand All @@ -84,9 +85,10 @@ BOOST_AUTO_TEST_CASE(connector__connect_address__bogus_address__operation_timeou
logger log{};
log.stop();
threadpool pool(2);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
const tiny_timeout set(bc::system::chain::selection::mainnet);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);
auto result = true;

boost::asio::post(strand, [&]() NOEXCEPT
Expand Down Expand Up @@ -114,9 +116,10 @@ BOOST_AUTO_TEST_CASE(connector__connect_authority__bogus_authority__operation_ti
logger log{};
log.stop();
threadpool pool(2);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
const tiny_timeout set(bc::system::chain::selection::mainnet);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);
auto result = true;

boost::asio::post(strand, [&, instance]() NOEXCEPT
Expand Down Expand Up @@ -144,9 +147,10 @@ BOOST_AUTO_TEST_CASE(connector__connect_endpoint__bogus_hostname__resolve_failed
logger log{};
log.stop();
threadpool pool(2);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
const tiny_timeout set(bc::system::chain::selection::mainnet);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);
auto result = true;

boost::asio::post(strand, [&, instance]() NOEXCEPT
Expand All @@ -172,10 +176,11 @@ BOOST_AUTO_TEST_CASE(connector__connect__stop__resolve_failed_race_operation_can
logger log{};
log.stop();
threadpool pool(2);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
settings set(bc::system::chain::selection::mainnet);
set.connect_timeout_seconds = 1000;
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);
auto result = true;

boost::asio::post(strand, [&, instance]()NOEXCEPT
Expand All @@ -202,10 +207,11 @@ BOOST_AUTO_TEST_CASE(connector__connect__started_start__operation_failed)
logger log{};
log.stop();
threadpool pool(2);
std::atomic_bool suspended{ false };
asio::strand strand(pool.service().get_executor());
settings set(bc::system::chain::selection::mainnet);
set.connect_timeout_seconds = 1000;
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set);
auto instance = std::make_shared<accessor>(log, strand, pool.service(), set, suspended);
auto result = true;

boost::asio::post(strand, [&, instance]() NOEXCEPT
Expand Down
8 changes: 6 additions & 2 deletions test/protocols/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class mock_acceptor
public:
mock_acceptor(const logger& log, asio::strand& strand,
asio::io_context& service, const settings& settings) NOEXCEPT
: acceptor(log, strand, service, settings), stopped_(false), port_(0)
: acceptor(log, strand, service, settings, suspended_),
stopped_(false), port_(0)
{
}

Expand Down Expand Up @@ -134,6 +135,7 @@ class mock_acceptor
private:
bool stopped_;
uint16_t port_;
std::atomic_bool suspended_{ false };
};

// Use mock connector to inject mock channel.
Expand All @@ -143,7 +145,8 @@ class mock_connector
public:
mock_connector(const logger& log, asio::strand& strand,
asio::io_context& service, const settings& settings) NOEXCEPT
: connector(log, strand, service, settings), stopped_(false)
: connector(log, strand, service, settings, suspended_),
stopped_(false)
{
}

Expand All @@ -169,6 +172,7 @@ class mock_connector

private:
bool stopped_;
std::atomic_bool suspended_{ false };
};

// Use mock p2p network to inject mock channels.
Expand Down
3 changes: 2 additions & 1 deletion test/sessions/session_inbound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class mock_p2p
acceptor::ptr create_acceptor() NOEXCEPT override
{
return ((acceptor_ = std::make_shared<Acceptor>(log, strand(),
service(), network_settings())));
service(), network_settings(), suspended_)));
}

session_inbound::ptr attach_inbound_session() NOEXCEPT override
Expand All @@ -332,6 +332,7 @@ class mock_p2p

private:
typename Acceptor::ptr acceptor_;
std::atomic_bool suspended_{ false };

class mock_inbound_session
: public session_inbound
Expand Down
3 changes: 2 additions & 1 deletion test/sessions/session_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class mock_p2p
connector::ptr create_connector() NOEXCEPT override
{
return ((connector_ = std::make_shared<Connector>(log, strand(),
service(), network_settings())));
service(), network_settings(), suspended_)));
}

session_inbound::ptr attach_inbound_session() NOEXCEPT override
Expand All @@ -253,6 +253,7 @@ class mock_p2p

private:
typename Connector::ptr connector_;
std::atomic_bool suspended_{ false };

class mock_inbound_session
: public session_inbound
Expand Down
6 changes: 4 additions & 2 deletions test/sessions/session_outbound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class mock_p2p
connector::ptr create_connector() NOEXCEPT override
{
return ((connector_ = std::make_shared<Connector>(log, strand(),
service(), network_settings())));
service(), network_settings(), suspended_)));
}

session_inbound::ptr attach_inbound_session() NOEXCEPT override
Expand All @@ -259,6 +259,7 @@ class mock_p2p

private:
typename Connector::ptr connector_;
std::atomic_bool suspended_{ false };

class mock_inbound_session
: public session_inbound
Expand Down Expand Up @@ -306,7 +307,7 @@ class mock_connector_stop_connect
mock_connector_stop_connect(const logger& log, asio::strand& strand,
asio::io_context& service, const settings& settings,
mock_session_outbound::ptr session) NOEXCEPT
: mock_connector_connect_success(log, strand, service, settings),
: mock_connector_connect_success(log, strand, service, settings, suspended_),
session_(session)
{
}
Expand All @@ -325,6 +326,7 @@ class mock_connector_stop_connect

private:
mock_session_outbound::ptr session_;
std::atomic_bool suspended_{ false };
};

// Can't derive from mock_p2p because Connector has more arguments.
Expand Down
6 changes: 4 additions & 2 deletions test/sessions/session_seed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class mock_p2p
connector::ptr create_connector() NOEXCEPT override
{
return ((connector_ = std::make_shared<Connector>(log, strand(),
service(), network_settings())));
service(), network_settings(), suspended_)));
}

session_inbound::ptr attach_inbound_session() NOEXCEPT override
Expand Down Expand Up @@ -272,6 +272,7 @@ class mock_p2p

private:
typename Connector::ptr connector_;
std::atomic_bool suspended_{ false };

class mock_inbound_session
: public session_inbound
Expand Down Expand Up @@ -321,7 +322,7 @@ class mock_connector_stop_connect
mock_connector_stop_connect(const logger& log, asio::strand& strand,
asio::io_context& service, const settings& settings,
mock_session_seed::ptr session) NOEXCEPT
: mock_connector_connect_success(log, strand, service, settings),
: mock_connector_connect_success(log, strand, service, settings, suspended_),
session_(session)
{
}
Expand All @@ -340,6 +341,7 @@ class mock_connector_stop_connect

private:
mock_session_seed::ptr session_;
std::atomic_bool suspended_{ false };
};

// Can't derive from mock_p2p because Connector has more arguments.
Expand Down

0 comments on commit 243444e

Please sign in to comment.